2
我已经在我的项目中设置了统一,并且它正在为那些没有实现构造函数注入的对象工作。现在的问题是我有一个对象,它需要一个自定义对象作为构造函数参数。我已经设置了配置的下方,这样的错误,告诉我, “的TypeConverter不能从System.String转换”统一构造函数
<unity>
<typeAliases>
<typeAlias alias="TransactionRepositoryInterface" type="Ib.TransactionViewer.DataAccess.ITransactionRepository, Ib.TransactionViewer.DataAccess" />
<typeAlias alias="TransactionRepositoryToUse" type="Ib.TransactionViewer.DataAccess.TransactionRepository, Ib.TransactionViewer.DataAccess" />
</typeAliases>
<containers>
<container>
<types>
<type type="TransactionRepositoryInterface" mapTo="TransactionRepositoryToUse">
<lifetime type="singleton" />
<typeConfig extensionType="Microsoft.Practices.Unity.Configuration.TypeInjectionElement, Microsoft.Practices.Unity.Configuration, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<constructor>
<param name="TransactionProcessor" parameterType="Ib.TransactionViewer.DataAccess.TransactionProcessor, Ib.TransactionViewer.DataAccess">
<value value="Ib.TransactionViewer.DataAccess.TransactionProcessor" type="Ib.TransactionViewer.DataAccess.TransactionProcessor, Ib.TransactionViewer.DataAccess" />
</param>
</constructor>
</typeConfig>
</type>
</types>
</container>
</containers>
</unity>
使用XML配置的要求?我更喜欢Fluent代码配置;我怀疑你会发现它更容易阅读和调试。 – TrueWill 2009-11-15 17:27:02