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
Method GetKeyedServices should allow you to get all keyed services.
Instead of adding correct override for that there was created this hack called "KeyedService.AnyKey"
The issues with this hack is that it doesn't work as intended. You would assume that its gonna return services for any key.
But no instead you have to name them the same.
Because this is confusing. I would propose adding just "provider.GetKeyedServices();" and remove AnyKey because it doesn't work as intended.
Reproduction Steps
services.AddKeyedSingleton<IMyType, MyType1>(typeof(MyType1).ToString());
services.AddKeyedSingleton<IMyType, MyType2>(typeof(MyType2).ToString());
access:
var list = provider.GetKeyedServices<IMyType>(KeyedService.AnyKey) // empty list
Expected behavior
Returns both services
Actual behavior
Returns empty list
Regression?
No response
Known Workarounds
services.AddKeyedSingleton<IMyType, MyType1>(KeyedService.AnyKey);
services.AddKeyedSingleton<IMyType, MyType2>(KeyedService.AnyKey);
access:
var list = provider.GetKeyedServices<IMyType>(KeyedService.AnyKey) // returns both
Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered:
Description
Method GetKeyedServices should allow you to get all keyed services.
Instead of adding correct override for that there was created this hack called "KeyedService.AnyKey"
The issues with this hack is that it doesn't work as intended. You would assume that its gonna return services for any key.
But no instead you have to name them the same.
Because this is confusing. I would propose adding just "provider.GetKeyedServices();" and remove AnyKey because it doesn't work as intended.
Reproduction Steps
Expected behavior
Returns both services
Actual behavior
Returns empty list
Regression?
No response
Known Workarounds
Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered: