Skip to content

Conversation

@abhiramch018
Copy link
Contributor

@abhiramch018 abhiramch018 commented Nov 25, 2025

…injection

Summary

Clarified that resolving services from the built-in .NET dependency injection (DI) container is thread-safe.

Changes

  • Updated the Thread safety section in dependency-injection-guidelines.md.
  • Added explicit statement that:
    • Service resolution via IServiceProvider and IServiceScope is thread-safe.
    • Service implementations themselves must still handle internal concurrency.
  • Added a note block for clarity.

Motivation

Resolves issue #47086 by explicitly documenting DI service resolution thread safety, which was previously implied but not stated.

Summary

Describe your changes here.

Fixes #Issue_Number (if available)


Internal previews

📄 File 🔗 Preview link
docs/core/extensions/dependency-injection-guidelines.md Dependency injection guidelines

…injection

### Summary
Clarified that resolving services from the built-in .NET dependency injection (DI) container is thread-safe.

### Changes
- Updated the **Thread safety** section in `dependency-injection-guidelines.md`.
- Added explicit statement that:
  - Service resolution via `IServiceProvider` and `IServiceScope` is thread-safe.
  - Service implementations themselves must still handle internal concurrency.
- Added a note block for clarity.

### Motivation
Resolves issue dotnet#47086 by explicitly documenting DI service resolution thread safety, which was previously implied but not stated.
@abhiramch018 abhiramch018 requested review from a team and IEvangelist as code owners November 25, 2025 12:18
@dotnetrepoman dotnetrepoman bot added this to the November 2025 milestone Nov 25, 2025
@dotnet-policy-service dotnet-policy-service bot added dotnet-fundamentals/svc community-contribution Indicates PR is created by someone from the .NET community. labels Nov 25, 2025
@abhiramch018
Copy link
Contributor Author

Hi @dotnet/docs
I’ve made the suggested updates for this issue.
Please take a quick look when you get a chance — happy to make any additional tweaks if needed.

Clarify thread safety and recommendations for DI usage.
@abhiramch018
Copy link
Contributor Author

Hi @IEvangelist,
Could you please take a quick look at this PR when you have a moment? It clarifies the thread safety of service resolution in .NET dependency injection, based on the guidance discussed in #47086. Appreciate your time and feedback!

Updated the dependency injection guidelines to improve clarity and correctness in the documentation.
@gewarren gewarren self-requested a review as a code owner December 22, 2025 18:57

- Property injection
- Injection based on name (.NET 7 and earlier versions only. For more information, see [Keyed services](dependency-injection.md#keyed-services).)
- Injection based on name (.NET 7 and earlier versions only–for more information, see [Keyed services](dependency-injection.md#keyed-services))
Copy link

@KalleOlaviNiemitalo KalleOlaviNiemitalo Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This item may give the wrong impression that injection based on name is only available in .NET 7 and earlier versions.

Now that .NET 7 is no longer supported, and later versions of Microsoft.Extensions.DependencyInjection still target .NET Standard 2.0 too, it might be better to remove the item altogether.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Indicates PR is created by someone from the .NET community. dotnet-fundamentals/svc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants