Update IServiceScopeFactory.CreateScope docs to clarify transient service disposal#124248
Update IServiceScopeFactory.CreateScope docs to clarify transient service disposal#124248
Conversation
Co-authored-by: rosebyte <14963300+rosebyte@users.noreply.github.com>
src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/IServiceScope.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: rosebyte <14963300+rosebyte@users.noreply.github.com>
Co-authored-by: rosebyte <14963300+rosebyte@users.noreply.github.com>
src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/IServiceScopeFactory.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/IServiceScope.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: rosebyte <14963300+rosebyte@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Updates XML documentation in DI Abstractions to clarify scope disposal behavior, aiming to address confusion around whether transient services resolved from a scope are disposed when the scope ends.
Changes:
- Updated
IServiceScopeFactory.CreateScope<returns>documentation to mention transient services in scope disposal. - Updated
IServiceScope<remarks>documentation with the same clarification.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/IServiceScopeFactory.cs | Updates CreateScope return docs to mention transient disposal at scope end. |
| src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/IServiceScope.cs | Updates IServiceScope remarks to mention transient disposal at scope end. |
src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/IServiceScopeFactory.cs
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/IServiceScope.cs
Show resolved
Hide resolved
🤖 Copilot Code Review — PR #124248Holistic AssessmentMotivation: The PR addresses a real documentation gap. The linked issue (#104472) describes user confusion about scope disposal behavior, particularly whether transient services are disposed. The implementation confirms that transient services implementing Approach: The approach of adding clarifying text to existing documentation is appropriate and low-risk. The change is minimal and focused on the stated goal. Summary: Detailed Findings
|
| Severity | Finding | Action |
|---|---|---|
| "any transient services" may be imprecise | Human reviewer should decide if precision or consistency is preferred | |
| ✅ | Implementation supports the claim | No action needed |
| 💡 | AsyncServiceScope consistency | Consider for follow-up |
Verdict:
Multi-model review synthesis: Claude Opus, GPT-5.2, and Gemini 3 Pro all flagged the precision issue. All agreed the change is directionally correct but noted the wording could be more precise.
|
Tagging subscribers to this area: @dotnet/area-extensions-dependencyinjection |
Description
API documentation for
IServiceScopeFactory.CreateScopeandIServiceScopestated that only "scoped services" are disposed when a scope ends. This omitted the fact that transient services are also tracked and disposed by scopes, leading to confusion about scope disposal behavior.Changes
Updated XML documentation in two files:
<returns>section to specify that both scoped services and transient services are disposed<remarks>section with same clarificationThe updated documentation now states:
This wording clarifies that transient services are disposed by scopes in a simple and concise manner, without explicitly mentioning disposal interface types (IDisposable/IAsyncDisposable). The simplified language addresses the core confusion raised in the original issue while keeping the documentation accessible.
This aligns with the actual DI container behavior and the guidance in Microsoft Learn documentation on disposable transient services captured by container.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.