给定注册服务:
builder.RegisterType<Foo1>().Named<IFoo>("one").As<IFoo>();
builder.RegisterType<Foo2>().Named<IFoo>("two").As<IFoo>();
builder.RegisterType<Foo3>().Named<IFoo>("three").As<IFoo>();
我可以IFoo
通过注入类似的东西来检索接口的命名实现Func<string, IFoo>
吗?
public class SomeClass(Func<string, IFoo> foo) {
var f = foo("one");
Debug.Assert(f is Foo1);
var g = foo("two");
Debug.Assert(g is Foo2);
var h = foo("three");
Debug.Assert(h is Foo3);
}
我知道我可以用它来做Meta<>
,但我不想用它。