Align keyed service tests with MS.DI spec and fix AnyKey enumeration#613
Merged
Conversation
…ationTests Update existing tests to match new MS.DI expected behavior (AnyKey registrations excluded from enumerations) and add 13 new tests covering combinational registration, AnyKey consistency/ordering, constructor/instance-provided AnyKey queries, and simple keyed resolution via IServiceFactory. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
When building IEnumerable<T> for a keyed service request, AnyKey ("*")
registrations should not appear in the results. Two cases fixed in
CreateEmitMethodForEnumerableServiceServiceRequest (both variance and
no-variance branches):
- GetKeyedServices(AnyKey): exclude services registered under "*" itself
- GetKeyedServices("some-key"): do not pull in "*" registrations as fallback
Single-service resolution with AnyKey wildcard fallback is unaffected.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Summary
KeyedMicrosoftTests.cswith the upstreamKeyedDependencyInjectionSpecificationTests.csfrom dotnet/runtime"*") registrations were incorrectly included inIEnumerable<T>keyed service resolutionChanges
Tests (
KeyedMicrosoftTests.cs)ResolveKeyedServicesAnyKeyWithAnyKeyRegistration: expects 4 services (not 5); AnyKey registrations are excluded from enumerationResolveKeyedServicesSingletonInstanceWithAnyKey: AnyKey registrations are not included when listing services by a specific keyResolveKeyedSingletonFromScopeServiceProviderandResolveKeyedScopedFromScopeServiceProvider: added assertions that direct AnyKey lookup throwsCombinationalRegistration,ResolveKeyedServicesAnyKeyConsistency,ResolveKeyedServicesAnyKeyConsistencyWithAnyKeyRegistration,ResolveKeyedServicesAnyKeyOrdering,ResolveWithAnyKeyQuery_Constructor,ResolveWithAnyKeyQuery_Constructor_Duplicates,ResolveWithAnyKeyQuery_InstanceProvided,ResolveWithAnyKeyQuery_InstanceProvided_Duplicates,ResolveRequiredKeyedServiceThrowsIfNotFound,SimpleServiceKeyedResolutionFix (
LightInject.cs)In
CreateEmitMethodForEnumerableServiceServiceRequest, two cases fixed (both variance and no-variance branches):GetKeyedServices(AnyKey): added&& k.ServiceName != "*"so the"*"registration itself is not returnedGetKeyedServices("some-key"): removed|| k.ServiceName == "*"so AnyKey wildcard registrations don't appear in specific-key enumerationsSingle-service resolution with AnyKey wildcard fallback is unaffected.
Test plan
🤖 Generated with Claude Code