我想使用Unity将字符串值注入到属性中。我找不到有效的语法。在本例中,PutBunniesHere
在这种情况下,错误是它没有将"type“识别为value的有效属性。我添加它是因为它不能解析之前的类型。
该类具有以下属性:
[Dependency("PutBunniesHere")]
public string PutBunniesHere { get; set; }
这是我用于unity的配置。
<?xml version="1.0" encoding="utf-8" ?>
<unity2 xmlns="http://schemas.microsoft.com/practices/2010/unity">
<alias alias="IInjectMe1" type="CommonLib.IInjectMe1, CommonLib"/>
<alias alias="singleton" type="Microsoft.Practices.Unity.ContainerControlledLifetimeManager, Microsoft.Practices.Unity" />
<container name="unity2">
<register type="CommonLib.IInjectMe2, CommonLib" name="Injected2" mapTo="CommonLib.InjectMe2, CommonLib">
<lifetime type="singleton"/>
<constructor>
<param name="theDependency" dependencyType="IInjectMe1" />
</constructor>
<property name="PutBunniesHere">
<value value="my bunnies" type="System.String"/>
</property>
</register>
</container>
</unity2>
发布于 2013-03-17 18:56:14
好了,问题解决了。同样,在register元素上有一个名称也是一个问题。这使得value元素上的值具有不同的含义。value表示已注册类型的名称,如果父register元素上有name属性,则表示类型。去掉名称和值就意味着一个值(也可能是一个类型)
啊哈。
https://stackoverflow.com/questions/15431059
复制相似问题