I have a interface called IRule and multiple classes that implement this interface. I want to uses the .NET Core dependency injection Container to load all implementation of
It's just a matter of registering all IRule
implementations one by one; the Microsoft.Extensions.DependencyInjection (MS.DI) library can resolve it as an IEnumerable
. For instance:
services.AddTransient();
services.AddTransient();
services.AddTransient();
services.AddTransient();
Consumer:
public sealed class Consumer
{
private readonly IEnumerable rules;
public Consumer(IEnumerable rules)
{
this.rules = rules;
}
}
NOTE: The only collection type that MS.DI supports is IEnumerable
.