-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Fix issues in GetKeyedService() and GetKeyedServices() with AnyKey #113137
base: main
Are you sure you want to change the base?
Conversation
…ey as the lookup key
Tagging subscribers to this area: @dotnet/area-extensions-dependencyinjection |
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.
PR Overview
This PR addresses inconsistencies in the resolution and caching behaviors for KeyedService.AnyKey. It updates the logic in service call site creation, modifies the service provider methods to validate AnyKey usage, and revises tests to ensure the correct behavior and exception throwing.
Reviewed Changes
File | Description |
---|---|
ServiceLookup/CallSiteFactory.cs | Adjusted the keys matching logic and caching behavior to exclude AnyKey registrations while preserving proper lookups. |
Specification.Tests/KeyedDependencyInjectionSpecificationTests.cs | Updated tests to reflect the revised expectations for service counts and exception throwing regarding AnyKey usage. |
ServiceProvider.cs | Added explicit checks to throw exceptions when AnyKey is used to resolve a non-collection service. |
ServiceLookup/ThrowHelper.cs | Introduced a helper method to throw an InvalidOperationException for invalid AnyKey resolution attempts. |
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Reviving the closed v9.0 PR #97561:
Semantics here mostly related to fallout and discussions from #95582. Here's a summary of IEnumerable-based queries that was copied from a test that was added in this PR: