Skip to content

Document service resolution thread safety and lifetime concurrency guidelines (Fixes #47086) - #56682

Open
Manish-1kumar wants to merge 2 commits into
dotnet:mainfrom
Manish-1kumar:users/manish/issue-47086-di-service-resolution-thread-safety
Open

Manish-1kumar wants to merge 2 commits into
dotnet:mainfrom
Manish-1kumar:users/manish/issue-47086-di-service-resolution-thread-safety

Conversation

@Manish-1kumar

@Manish-1kumar Manish-1kumar commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Addresses issue #47086 by adding clear thread safety documentation to docs/core/extensions/dependency-injection/service-lifetimes.md:

  • Added a dedicated ## Thread safety considerations section.
  • Explicitly confirmed that resolving services from the built-in dependency injection container (IServiceProvider) or active scope (IServiceScope) is thread-safe across concurrent threads.
  • Clarified concurrency expectations across singleton (must be thread-safe) and transient/scoped services (resolution is thread-safe, but instances themselves are not inherently safe to share across threads).
  • Cross-linked to guidelines.md#thread-safety and added ## See also links.

Fixes #47086.


Internal previews

File Preview link
docs/core/extensions/dependency-injection/service-lifetimes.md Learn preview

Build report

@dotnetrepoman dotnetrepoman Bot added this to the November 2026 milestone Nov 1, 2026
@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 1, 2026
@Manish-1kumar
Manish-1kumar force-pushed the users/manish/issue-47086-di-service-resolution-thread-safety branch from 09df433 to d370f47 Compare November 30, 2026 17:40
@BillWagner
BillWagner requested a balanced review from Copilot December 2, 2026 17:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The article’s ms.date remains 10/21/2025 and needs updating to reflect the substantive content refresh.

1 open issue
What changed in this PR

Addresses #47086 by documenting thread-safe service resolution and lifetime-specific concurrency expectations in the .NET dependency injection guidance.

Changes:

  • Distinguishes container resolution safety from service-instance thread safety.
  • Adds links to related guidelines and the dependency injection overview.
File Description
docs/​core/​extensions/​dependency-injection/​service-lifetimes.md Adds thread-safety guidance and related links.

Review effort: Balanced


In apps that process requests, singleton services are disposed when the <xref:Microsoft.Extensions.DependencyInjection.ServiceProvider> is disposed on application shutdown. Because memory isn't released until the app shuts down, consider memory use with a singleton service.

## Thread safety considerations

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have updated ms.date to 12/03/2026 in 4750c39.

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.

There is no clear indication whether resolving services from DI is thread safe

2 participants