Correct keyed-service probing for built-in DI services#128198
Merged
Conversation
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-serviceprocess |
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/f4149def-49de-43e5-84a5-a346b3d05cc4 Co-authored-by: rosebyte <14963300+rosebyte@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/f4149def-49de-43e5-84a5-a346b3d05cc4 Co-authored-by: rosebyte <14963300+rosebyte@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix misleading claims about built-in services as keyed services
Correct keyed-service probing for built-in DI services
May 14, 2026
rosebyte
approved these changes
May 14, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes keyed-service probing in the default Microsoft.Extensions.DependencyInjection provider so built-in DI services are reported as keyed-resolvable only when the service key is null, matching actual resolution behavior.
Changes:
- Gates built-in DI service fallback in
CallSiteFactory.IsServiceonServiceKey is null. - Adds specification regression coverage for the four built-in DI service types with null, non-null, and
KeyedService.AnyKeyprobes.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/CallSiteFactory.cs |
Aligns built-in service probing with keyed resolution semantics. |
src/libraries/Microsoft.Extensions.DependencyInjection.Specification.Tests/src/ServiceProviderIsKeyedServiceSpecificationTests.cs |
Adds regression coverage for keyed probing of built-in DI services. |
This was referenced May 15, 2026
Open
mrek-msft
approved these changes
May 19, 2026
svick
approved these changes
May 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
IServiceProviderIsKeyedServicewas reporting built-in DI service types as available for arbitrary keys, while actual keyed resolution correctly failed. This change aligns probing with resolvability by treating built-ins as available only for the null key.Behavior fix (
CallSiteFactory.IsService)IServiceProvider,IServiceScopeFactory,IServiceProviderIsService,IServiceProviderIsKeyedService) toserviceKey is null.AnyKeylookup behavior for explicitly registered keyed services.Regression coverage (spec tests)
IsKeyedService(type, null) == trueIsKeyedService(type, nonNullKey) == falseIsKeyedService(type, KeyedService.AnyKey) == falseFixes #127537