我想确保unity使用命名注册来解析构造函数参数,例如:
我有两个类型注册:
_container.RegisterType<IMyInterface, Implementation1>("implementation1");
_container.RegisterType<IMyInterface, Implementation2>("implementation2");
当unity使用以下构造器解析一个类时:
public class Example
{
Example(IMyInterface args)
{
}
}
在这种情况下,我应该如何指定必须使用"implementation2“来解析的unity
发布于 2013-06-12 18:56:07
您可以在Unity中配置类型注册,以使用以下内容将构造函数参数解析为特定的命名类型:
container.RegisterType<IExample, Example>(
new InjectionConstructor(new ResolvedParameter<IMyInterface>("implementation2")));
https://stackoverflow.com/questions/17071951
复制