Configuration 统一IOC配置
我有一节课Configuration 统一IOC配置,configuration,unity-container,Configuration,Unity Container,我有一节课 public class Broker { public Broker(string[] hosts, string endPoint, string port, Type remoteType) { } } 我想使用UnityXML配置对其进行配置,我可以使用C#中的代码对其进行配置,如下所示,“container”是我的Unity容器 container.Configure<InjectedMembers>()
public class Broker
{
public Broker(string[] hosts, string endPoint, string port, Type remoteType)
{
}
}
我想使用UnityXML配置对其进行配置,我可以使用C#中的代码对其进行配置,如下所示,“container”是我的Unity容器
container.Configure<InjectedMembers>()
.ConfigureInjectionFor<Broker>("myBroker",
new InjectionConstructor(hosts, endPoint, port, new InjectionParameter(typeof(IMyBrokeredObject))));
container.Configure()
.ConfigureInjectionFor(“myBroker”,
新的InjectionConstructor(主机、端点、端口、新的InjectionParameter(typeof(IMyBrokeredObject)));
它将很高兴地解决使用正常的团结呼吁
容器。解决(“myBroker”)
但是目前我的xml无法解析最后一个参数IMyBrokeredObject,我得到了一个解析异常,因为Unity试图解析类型,而不是像上面代码中那样简单地注入类型
有什么想法吗?您是否在配置文件中定义了类型:
<unity>
<typeAliases>
<typeAlias alias="IMyBrokeredObject" type="MyAssembly.IMyBrokeredObject, MyAssembly" />
</typeAliases>
<containers>
<container>
<types>
<!-- Views -->
<type type="IMyBrokeredObject" mapTo="MyAssembly.MyBrokeredObjectImplementation, MyAssembly" />
但我的问题是,IMyBrokeredObject没有可用的实现,在这种背景下实际发生的是,代理提供了一个接口的远程对象,实际的实现在其他地方 在代码中,我可以通过提供“InjectionParameter”让容器提供代理,但在xml配置中我找不到如何做到这一点 这很棘手,因为我不希望容器给出接口的实例,但实际上要按原样传递接口,“InjectionParameter”是值的存储,存储的值在容器创建对象时按原样提交。我要寻找的是创建InjectionParameter并为其提供值所需的配置xml(如果可能的话)