-
Notifications
You must be signed in to change notification settings - Fork 5k
FromServiceKeyAttribute to support nullable (for unkeyed) and to use current service key #114929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
… to use current service key
Note regarding the
|
1 similar comment
Note regarding the
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR updates the handling of keyed services to support nullable (unkeyed) services and to use the current service key by distinguishing between lookup modes.
- Refactored CallSiteFactory logic to separate InheritKey and ExplicitKey scenarios.
- Updated FromKeyedServicesAttribute to set LookupMode based on whether the provided key is null.
- Added tests for resolving both keyed and unkeyed services.
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/CallSiteFactory.cs | Updated keyed resolution logic to handle InheritKey and ExplicitKey modes. |
src/libraries/Microsoft.Extensions.DependencyInjection.Specification.Tests/src/KeyedDependencyInjectionSpecificationTests.cs | Added tests for resolving services under various key scenarios, including unkeyed services. |
src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/ServiceKeyLookupMode.cs | Introduced ServiceKeyLookupMode with three possible modes. |
src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/FromKeyedServicesAttribute.cs | Modified attribute constructor to set LookupMode appropriately. |
src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/ref/Microsoft.Extensions.DependencyInjection.Abstractions.cs | Updated public API reference to reflect the changes in the attribute constructors and enum. |
src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/CallSiteFactory.cs
Show resolved
Hide resolved
I applied the API review feedback from #113585 (comment). @stephentoub @halter73 can you please have a review? |
...ries/Microsoft.Extensions.DependencyInjection.Abstractions/src/FromKeyedServicesAttribute.cs
Show resolved
Hide resolved
...ries/Microsoft.Extensions.DependencyInjection.Abstractions/src/FromKeyedServicesAttribute.cs
Show resolved
Hide resolved
...ries/Microsoft.Extensions.DependencyInjection.Abstractions/src/FromKeyedServicesAttribute.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/ServiceKeyLookupMode.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/ServiceKeyLookupMode.cs
Outdated
Show resolved
Hide resolved
Added When you commit this breaking change:
Tagging @dotnet/compat for awareness of the breaking change. |
Fixes #113585
(draft to verify tests)
This is API approved except for this which is being done via email: