Skip to content

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

Open
@emardini

Description

@emardini

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions