Description
.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 this
public interface IKeyedServiceProvider
{
IReadOnlyDictionary<object?, T> GetServices<T>();
}
Along with extensions similar to the following
IReadOnlyDictionary<TKey, T> GetServices<TKey, T>()
Or add an extension on IServiceProvider that allows the above 2 methods.