Register multiple implementations with single interface
You can register multiple implementation of the same interface with using the RegisterCollection
method (see documentation: Configuring a collection of instances to be returned)
So you need to write:
container.Collection.Register<IInterface1>(typeof(Myclass1), typeof(Myclass2));
And now Simple Injector can inject a collection of Interface1
implementation into your constructor, for example:
public class Foo
{
public Foo(IEnumerable<IInterface1> interfaces)
{
//...
}
}
Or you can explicitly resolve your IInterface1
implementations with GetAllInstances
:
var myClasses = container.GetAllInstances<IInterface1>();