Search code examples
asp.net-coredependency-injection.net-corecastle-windsor

Net core equivalent of Castle Windsor ResolveAll


I trying to move my old my NetFramwork project made with Castle Windsor to netcore. I'm trying to replace this nuget package with the Microsoft.Extensions.DependencyInjection package but i don't find an equivalent for convert this code:

 container.Register(Component.For<IInterface1>>().ImplementedBy<Class1>().Named(nameof(v1)));
 container.Register(Component.For<IInterface1>>().ImplementedBy<Class2>().Named(nameof(v2)));

and the resolve all using:

 kernel.ResolveAll(IInterface1);

Is there a way to do this using IServiceProvider?


Solution

  • .GetServices<TService>() extension method on IServiceProvider

    IEnumerable<IInterface1> variable = service.GetServices<IInterface1>().