dotnet / dotnet/docs

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

Open
#46,061 0 comments 0 reactions 0 assignees View on GitHub
:watch: Not Triaged dotnet-fundamentals/svc
Dominant language
No language data
Stars
4.8k
Forks
6.1k
Avg merge
19h 10m
Merged PRs (30d)
268

Description

### 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](https://github.com/dotnet/docs/issues?q=is%3Aissue+is%3Aopen+5a2fc6e8-a47b-c300-1ef0-e6ae89612d74)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.