0

我想使用 Unity 将字符串值注入到属性中。我找不到有效的语法。在这种情况下,PutBunniesHere

在这种情况下,错误是它没有将“类型”识别为值的有效属性。我补充说,因为它以前无法解析类型。

该类具有以下属性:

    [Dependency("PutBunniesHere")]
    public string PutBunniesHere { get; set; }

这是我用于统一的配置。

<?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>
4

1 回答 1

0

好的,解决了问题。再一次,在 register 元素上有一个名字是个问题。这使得 value 元素上的 value 具有不同的含义。value 表示已注册类型的名称,或者如果父 register 元素上有 name 属性,则表示类型。取出名称和值意味着一个值(也可能是一个类型)

玉。

于 2013-03-17T10:56:13.910 回答