docs icon indicating copy to clipboard operation
docs copied to clipboard

Is it possible to recommend a different approach or improve on this one?

Open emardini opened this issue 7 months ago • 0 comments

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

  • ID: ca143da3-5c97-0dc0-9d99-ed477a8bce91
  • PlatformId: a6310155-bcdf-f5b9-b058-c635e4438048
  • Service: dotnet-fundamentals

Related Issues

emardini avatar May 09 '25 02:05 emardini