mardi 6 février 2018

How to register DI services for specific Interface type?

I have interface IServiceHandlerAsync<T> and I have following service registrations

services.AddScoped<SoftwareTestService>();
services.AddScoped<SoftwareTestCaseService>();
services.AddScoped<SoftwareTestCaseStepService>();
services.AddScoped<SoftwareTestCaseStepResultService>();

where each of these services are inherited from interface IServiceHandlerAsync<T>

is it possible to resolve and register aforamentioned services without specifying every service explicitely by using interface (I am thinking that reflection may do the work) ?

Algorithmic example would be

foreach (var service in .getResolvedServices<IServiceHandlerAsync>)
{
    services.AddScoped(service);
}





Aucun commentaire:

Enregistrer un commentaire