-
Notifications
You must be signed in to change notification settings - Fork 6k
Imprecise note wording regarding the use of scoped services? #45617
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
Yeah, this can be a bit confusing and hard to articulate. Thanks for posting this issue @fterrani, would you be interested in proposing a PR to address this? The main idea is that if you have a Singleton or Transient service, and you try requiring a service that's registered as Scoped in the |
@IEvangelist I can try, but I cannot guarantee anything since my understanding of that topic isn't deep enough and I'm not sure I'll find the time. I'll get back to you here and/or via a PR if I manage to come up with something. |
@IEvangelist Thanks for the fix 👍 |
Uh oh!
There was an error while loading. Please reload this page.
Type of issue
Missing information
Description
The note in the Scoped section seems imprecise to me:
When reading this, one could think using a scoped service from a singleton service is absolutely forbidden in any scenario. However, this looks contradictory with what's shown there in those pages/section regarding
IServiceScopeFactory
:Maybe my wording is incorrect, but to me, a scoped service is indeed resolved and ends up being injected in a singleton service in these situations. It's just that it is not done badly via constructor or
IServiceProvider
but cleanly from within a scope created withIServiceScopeFactory.CreateScope()
in the singleton service. I think the meaning of resolving a scoped service from a singleton isn't clear enough and that the following introduction could be used to make the message clearer:In other words, while conforming to the current version of the note is a sufficient condition, using a scope seem to be a necessary and sufficient condition that is worth mentioning.
Page URL
https://learn.microsoft.com/en-us/dotnet/core/extensions/dependency-injection#scoped
Content source URL
https://github.com/dotnet/docs/blob/main/docs/core/extensions/dependency-injection.md
Document Version Independent Id
cc5f00d0-fb50-1229-8fa2-e66b1f45b284
Platform Id
7f5b5732-fc3e-6ffb-b8b8-77b5659a8015
Article author
@IEvangelist
Metadata
Related Issues
Associated WorkItem - 417526
The text was updated successfully, but these errors were encountered: