-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Add a way to get IReadOnlyDictionary<,> of keyed services #95476
Comments
Tagging subscribers to this area: @dotnet/area-extensions-dependencyinjection Issue Details.net 8 introduced a way to register keyed services which is great. However, what if one wants to get a list of services along with it's key. For example, during run time, I want to present the user a menu of available services. The user will select the default service to use. Without a way to expose the registration key, there is no real easy way to identify the keyed service. I think the missing piece here is the ability to be able to inject
|
I don’t think we’d do it that way but I agree with the sentiment that this feature is missing. |
@davidfowl thanks for your comment. Other using a dictionary, how would you do it? I updates my Issue by providing alternative solution using a provider. |
Your dictionary may need to take into account that for the same service key and service type multiple services may have been registered, with different implementation types, instances or factories but with the same service type. |
The proposal here adds to the existing interface |
@benjaminpetit thoughts? |
Any update on this? |
.NET 8 introduced a way to register keyed services which is great addition. However, what if one wants to get a list of registered services along with their key. For example, during run time, I want to present the user a menu of some sort with all available services. The user will select the default service to use for the app. Without a way to expose the registered key, there is no real easy way to identify the keyed service and its key.
I think the missing piece here is the ability to be able to inject
IReadOnlyDictionary<object?, object>
which it'll be resolved by the IoC container. Alternatively, we can have a service with something like thisAlong with extensions similar to the following
Or add an extension on IServiceProvider that allows the above 2 methods.
The text was updated successfully, but these errors were encountered: