1

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?

Steven
  • 166,672
  • 24
  • 332
  • 435
kalitsov
  • 1,319
  • 3
  • 20
  • 33

1 Answers1

2

Make constructor argument a collection

public class MyController
{
    public MyController(IEnumerable<ICustomService> myServices) { }
}
Fabio
  • 31,528
  • 4
  • 33
  • 72