Add IServiceScope support
#245
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds support for scoped services from the service provider using IServiceScope without taking a dependency on
Microsoft.Extensions.DependencyInjection.Abstractions.Motivation
I want to implement an
IUserAuthenticatorthat consumes aUserManager<AppUser> userManagerfrom ASP.NET Core Identity. This is typically registered as a scoped service.ISessionContext.ServiceProviderdoes however return the root SP. I think SMTP is a rather good fit for thescopedscenario. As a scope in Http corresponds to one request, a scope in Smtp can correspond to one Smtp session (one could argue it could also correspond to one SmtpCommand but I think the connection makes more sense for SMTP, given it is stateful).Usage
If this is merged, one can easily add a class like this in his codebase that does depend on
Microsoft.Extensions.DependencyInjection.Abstractions:And register this class in the app's DI container like this: