1
votes

The ASP.NET Core built-in dependency injection mechanism allows to have multiple service registrations to the same interface type:

    public void ConfigureServices(IServiceCollection services)
    {
        ...                   
        services.AddScoped<ICustomService, CustomService1>();
        services.AddScoped<ICustomService, CustomService2>();
        services.AddScoped<ICustomService, CustomService3>();
        ...
    }

While the last service registered get a precedence when the requested service is resolved:

public MyController(ICustomService myService) { }

I'm wandering how can i get the full list of registered services of a given type in my controller constructor eg. ICustomService?

1

1 Answers

2
votes

Make constructor argument a collection

public class MyController
{
    public MyController(IEnumerable<ICustomService> myServices) { }
}