You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The relatively new feature of keyed services seems to have a bug. I would not expect a keyed service to be returned from the non-keyed call to IServiceProvider.GetServices<T>() extension method.
Reproduction Steps
usingMicrosoft.Extensions.DependencyInjection;varservices=newServiceCollection();services.AddKeyedTransient<TestProcessor>("test123");awaitusingvarprovider=services.BuildServiceProvider();for(vari=0;i<10;i++){varprocessors=newList<TestProcessor>();// Common pattern for combining both specific and global logic.processors.AddRange(provider.GetKeyedServices<TestProcessor>("test123"));processors.AddRange(provider.GetServices<TestProcessor>());// Only a single processor is registered, so this should always be 1?Console.WriteLine("Processor count: {0}",processors.Count);// Not sure why the delay makes a difference, but it does.awaitTask.Delay(1);}sealedclassTestProcessor{}
Expected behavior
The number of processors resolved should be consistent with each invocation. The number of processors resolved should equal one.
Description
The relatively new feature of keyed services seems to have a bug. I would not expect a keyed service to be returned from the non-keyed call to
IServiceProvider.GetServices<T>()
extension method.Reproduction Steps
Expected behavior
The number of processors resolved should be consistent with each invocation. The number of processors resolved should equal one.
Actual behavior
Regression?
Does not appear to be a regression (reproducible with
Microsoft.Extensions.DependencyInjection
v8.0.0).Known Workarounds
No response
Configuration
.NET SDK 9.0.102
Windows 11 10.0.26100
Other information
No response
The text was updated successfully, but these errors were encountered: