-
Notifications
You must be signed in to change notification settings - Fork 5k
Respect ServiceLifeTime during resolution #36050
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
Comments
It's pretty much a corner case, best we could do is add a flag to turn it off bu ti's pretty low priority and we have no plans to change the default behavior. What are you expecting the behavior to be here? |
I realize that changing the logic for resolve may be "none-trivial". That's why I mentioned a way to determine if the current solution provider is scoped or not. This seems to have been considered at some stage, as CallSiteKind already has an enumeration "Scope". Having the service provider return the current scope when resolving IServiceScope (like VisitServiceProvider does for IServiceProvider), and including something like IsRoot or GetParentScope() in IServiceScope. However...
That can surely be optimized, but the gist ist there. |
Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process. This process is part of our issue cleanup automation. |
This issue will now be closed since it had been marked |
Currently it is not possible to register a service interface scoped and singleton with different implementations, e.g.
services.AddSingelton<IMyInterface, GlobalEngine>();
services.AddScoped<IMyInterface, ScopedEngine>();
A call to "sp.GetService()" on the global service provider will either raise
an exception ("InvalidOperationException: Cannot resolve scoped service '{0}' from root provider.")
or resolve ScopedEngine, depending on ServiceProviderOptions.ValidateScopes.
Also I have no way of working around that issue, since there is no way to ask the IServiceProvider whether it is scoped or not.
Best solution would be, if a resoluton on the global service provider ignored scoped definitions.
Next best solution would be some way to determine if the current solution provider is scoped or not.
PS: I realize that this is a corner case and I'm usually fine with restrictions - as long as I can find workarounds.
The text was updated successfully, but these errors were encountered: