我有一节课
public class Broker
{
public Broker(string[] hosts, string endPoint, string port, Type remoteType)
{
}
}我想使用Unity XML Configuration来配置它,我可以使用C#中的代码来配置它,如下所示,其中" container“是我的Unity容器
container.Configure<InjectedMembers>()
.ConfigureInjectionFor<Broker>("myBroker",
new InjectionConstructor(hosts, endPoint, port, new InjectionParameter(typeof(IMyBrokeredObject))));并且它将使用普通的unity调用来迅速解决
container.Resolve("myBroker");
但是目前我的xml不能解析最后一个参数IMyBrokeredObject,我得到了一个解析异常,因为Unity试图解析简单地注入类型的类型实例,就像上面的代码所做的那样。
有什么想法吗?
发布于 2008-12-29 17:55:02
您是否在配置文件中定义了类型:
<unity>
<typeAliases>
<typeAlias alias="IMyBrokeredObject" type="MyAssembly.IMyBrokeredObject, MyAssembly" />
</typeAliases>
<containers>
<container>
<types>
<!-- Views -->
<type type="IMyBrokeredObject" mapTo="MyAssembly.MyBrokeredObjectImplementation, MyAssembly" />发布于 2009-01-02 15:43:02
但我的问题是,IMyBrokeredObject没有可用的实现,在此背景下实际发生的情况是,代理在给定接口的情况下提供远程对象,实际的实现在其他地方。
在代码中,我可以通过提供一个"InjectionParameter“来让容器提供一个代理,但我不知道如何在xml配置中做到这一点。
这很棘手,因为我不想让容器给出接口的实例,而是按原样传递接口,"InjectionParameter“是一个值的存储,当容器按原样创建对象时,存储的值被提交。我正在寻找的是创建InjectionParameter并为其赋值所需的配置xml,如果可能的话?
https://stackoverflow.com/questions/371005
复制相似问题