鉴于下面的小例子,有没有办法在 中标记(属性,名称约定,...)MyInterface参数MyService2,以便它能够正确解析,或者是传入的唯一方法MyInterface[]?我知道 Castle Windsor 可以根据命名约定来解决它,但我在 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>();
}
}