Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scoped service lifetime #116

Closed
yallie opened this issue Jan 15, 2025 · 1 comment
Closed

Scoped service lifetime #116

yallie opened this issue Jan 15, 2025 · 1 comment

Comments

@yallie
Copy link
Collaborator

yallie commented Jan 15, 2025

Is your feature request related to a problem? Please describe.
Suppose we have a service that should be shared within the current remote call.
For example, each remote call should produce a single log file, and all services should write to this log file.
Multiple concurrent remote call should write to different files and not interfere with one another.

Describe the solution you'd like
This is a common concept known as scoped service lifetime.
It's supported by most IoC containers out of the box, i.e. Castle.Windsor, DryIoc, Autofac, Microsoft, etc.
The example task above is solved by registering a scoped logger service that creates a log file per remote call.

Describe alternatives you've considered
It's possible to write scoped containers in the user code using BeforeCall/AfterCall event to create scopes.
But then scoped services cannot be registered using the built-in DI container interface.
It becomes cumbersome and counterintuitive as opposed to the built-in scoped service support.

yallie added a commit to yallie/CoreRemoting that referenced this issue Jan 15, 2025
@yallie
Copy link
Collaborator Author

yallie commented Jan 15, 2025

Public API changes summary:

  1. ServiceLifetime enum gets the Scoped member.
  2. IDependencyInjectionContainer interface gets new IDisposable CreateScope() method.

@yallie yallie closed this as completed in 73a7f32 Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant