Skip to content
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 #14799

Closed
MikeAlhayek opened this issue Nov 30, 2023 · 2 comments
Closed

Add a way to get IReadOnlyDictionary<,> of keyed services #14799

MikeAlhayek opened this issue Nov 30, 2023 · 2 comments
Milestone

Comments

@MikeAlhayek
Copy link
Member

MikeAlhayek commented Nov 30, 2023

Add a way to provide IReadOnlyDictionary<,> of keyed service

@MikeAlhayek MikeAlhayek changed the title Add a way to resolve IDictionary<,> from keyed service Add a way to get IReadOnlyDictionary<,> of keyed services Dec 3, 2023
@sebastienros
Copy link
Member

I would rather add some options metadata together with the registration of the keyed services (and that works also non-keyed services).

Example:

services.AddKeyedTransient<IService, Service1>("a");
services.AddKeyedTransient<IService, Service2>("b");

options.AvailableIServices.Add("a", "This is the best IService", "logo.png");
options.AvailableIServices.Add("b", "This is the second best IService", "logo2.png");

And usually you would have an extension method to add both the service and the registration in the options:

services.AddAwesomeServices<Service1>("a"); // where T : IService
services.AddAwesomeServices<Service2>("b");

Then you can list all available services, and their description. Then store "a" or "b" in the database for the selected one. And use the key to resolve the service.

With non-keyed services you can also store the type directly in the metadata.

@Piedone
Copy link
Member

Piedone commented Mar 22, 2024

This will be part of .NET, so we don't need to do it, see dotnet/runtime#95476.

@Piedone Piedone closed this as not planned Won't fix, can't repro, duplicate, stale Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants