Given the small example below, is there a way to mark (attribute, name convention,... ) the MyInterface
argument in MyService2
, so that it will resolve correctly, or is the only way to pass in MyInterface[]
?
I know that Castle Windsor can resolve it based on naming convention, but I haven't found something similar in DryIoc
public interface MyInterface { }
public class MyImplementationA : MyInterface { }
public class MyImplementationB : MyInterface { }
public class MyService1
{
public MyService1(MyInterface[] implementations) {
Console.WriteLine(implementations.GetType().Name);
}
}
public class MyService2
{
public MyService2(MyInterface implementationA) {
Console.WriteLine(implementationA.GetType().Name);
}
}
class Program
{
static void Main(string[] args)
{
var c = new Container();
c.Register<MyInterface, MyImplementationA>(serviceKey: "implementationA");
c.Register<MyInterface, MyImplementationB>(serviceKey: "implementationB");
c.Register<MyService1>();
c.Register<MyService2>();
var a = c.Resolve<MyService1>();
var b = c.Resolve<MyService2>();
}
}