Support keyed service for variant service provider#606
Conversation
|
|
||
| private TService ResolveVariantService(string variantName) | ||
| { | ||
| if (_serviceProvider is IKeyedServiceProvider) |
There was a problem hiding this comment.
it's behavioural BC. if there is keyed di compatible user he'll need to change his whole DI setup after update
There was a problem hiding this comment.
i think you forgot that useKeyedService option
There was a problem hiding this comment.
Yes. I discussed with @jimmyca15. The discussion result is to not have useKeyedService toggle.
it's behavioural BC. if there is keyed di compatible user he'll need to change his whole DI setup after update
This is not a breaking change, because we have fallback logic, it will first try to get keyed service and if there is no keyed service match the variant name, it will still use the previous way (GetRequiredService<IEnumerable>()) to get all implementation and inspect them one by one.
Why this PR?
#605 #564
VariantServiceProvider<TService>previously took IEnumerable, which forced the DI container to instantiate every registered implementation ofTServiceat construction time — even variants that would never be selected. This PR changes it to take the IServiceProvider directly and, at runtime, checks whether a keyed service can be retrieved; if so, lazy on-demand instantiation is achieved.Thanks @Stepami for bringing the keyed service implementation to us, and for clarifying and addressing our compatibility concerns.