-
Notifications
You must be signed in to change notification settings - Fork 14
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
Transient registrations in ServiceCollection are mapped to PerRequestLifetime #13
Comments
The reason that we map transient to the PerRequestLifetime is solely because of the specification tests that each adapter needs to pass. The default implementation (Microsoft.Extensions.DependencyInjection) operates with what they call the "root scope" that basically means that a scope is started when the container is created. Transients requested outside an explicit scope will therefore be released when the container is released. I guess the problem is what to do with disposable transients and when they should be disposed. We could however do a check for this by looking at the service type and the implementing type if available (could be a factory expression where the implementing type is unknown) and only register with the PerRequestLifetime if the service appears to be disposable. btw, this library you are talking about, is it here on GitHub? |
Thank you for explanation, Bernhard it really helped. |
Fixed by #23 |
It seems that transient registrations in ServiceCollection are mapped to PerRequestLifetime. So they will not be resolved without scope. But it gives different semantics to the lifetime of registered service because they are not truly transient anymore. I am building some reusable library for asp.net core applications so i am sticked to rather general approach here - use IServiceCollection extensions of form "services.UseSomeLibrary()". My design requires transient service to be resolved in background, outside of any scope like HttpRequest so they are registered with transient lifetime. When i use this library with LightInject container in the same app then my library is broken because transient background services are not resolved due to absence of scope. Is not it better to map transient lifetime of ServiceCollection to real transient registrations in LightInject?
The text was updated successfully, but these errors were encountered: