Dependency Injection - interfaces in a Dictionary c#

Viewed 49

I want to inject a IDictionary of {key, interface} into a contructor, but I have no idea how to set it up in the program.cs

I can initiate the Interfaces and I can could initiate an IDictionary but I have no idea how to combine them.

Any suggestions would be appriciated.

Additional Context:

So i need to inject my services like

I need to inject the services eg,

s.AddTransient<IFooService, AFooService>();
s.AddTransient<IFooService, BFooService>();

but in the contructor I want

public MyClass(IDictionary<string, IFooService> fooServices)
1 Answers
services.AddTransient<MyClass>();
services.AddTransient<AFooService>();
services.AddTransient<BFooService>();

services.AddTransient<IDictionary<string, IFooService>>(sp =>
    new Dictionary<string, IFooService>
    {
        { "A", sp.GetRequiredService<AFooService>() },
        { "B", sp.GetRequiredService<BFooService>() },
    });
``
Related