Is it possible to recommend a different approach or improve on this one? · Issue #46061 · dotnet/docs · GitHub
More Web Proxy on the site http://driver.im/
You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While injecting a service factory or service provider could overcome the issue of injecting scoped dependencies into a background job, it can create problems, for example, the service call could blow up during the execution due to a misconfiguration and not during the construction which is what we want our DI to do, the recommendation in this documentation while works may bring its own set of problems.
I wonder if instead of doing this, we can simply register the same dependency twice: one as a singleton and another one as scoped, the DI will pick the most suited for each case.
Which problems do you see with this approach? At worst, it could be wortwhile to discuss the pitfalls of injecting a service locator, for example, checking for errors while trying to locate the dependency.
emardini
changed the title
Is it possible to recommend a different approach
Is it possible to recommend a different approach or improve on this one?
May 9, 2025
Uh oh!
There was an error while loading. Please reload this page.
Type of issue
Typo
Description
While injecting a service factory or service provider could overcome the issue of injecting scoped dependencies into a background job, it can create problems, for example, the service call could blow up during the execution due to a misconfiguration and not during the construction which is what we want our DI to do, the recommendation in this documentation while works may bring its own set of problems.
I wonder if instead of doing this, we can simply register the same dependency twice: one as a singleton and another one as scoped, the DI will pick the most suited for each case.
Which problems do you see with this approach? At worst, it could be wortwhile to discuss the pitfalls of injecting a service locator, for example, checking for errors while trying to locate the dependency.
Page URL
https://learn.microsoft.com/en-us/dotnet/core/extensions/scoped-service
Content source URL
https://github.com/dotnet/docs/blob/main/docs/core/extensions/scoped-service.md
Document Version Independent Id
5a2fc6e8-a47b-c300-1ef0-e6ae89612d74
Platform Id
a6310155-bcdf-f5b9-b058-c635e4438048
Article author
@IEvangelist
Metadata
Related Issues
The text was updated successfully, but these errors were encountered: