Spring.NET - IList的构造函数参数
我正在尝试将 IList 注入构造函数,并想知道这是否可能,如果可以,有人可以启发我吗?事实上它要求一个类型转换器让我觉得我做不到。
我尝试过...
<object name="DataLayer.DataServices.IGetAccountDatabase" type="DataServices.LinqToEntities.EntityDataModel, DataServices.LinqToEntities" singleton="false"></object>
<object name="DataLayer.DataServices.IGetAccountMessage" type="DataServices.VMX.VmxModel, DataServices.VMX" singleton="false"></object>
<object name="DataLayer.DataServices.IDataService" type="DataServices.NavigationModel, DataServices" singleton="false">
<constructor-arg>
<list element-type="DataLayer.DataServices.IGetAccount, DataLayer" >
<idref object="DataLayer.DataServices.IGetAccountMessage"/>
<idref object="DataLayer.DataServices.IGetAccountDatabase"/>
</list>
</constructor-arg>
</object>
创建名为“DataLayer.DataServices.IDataService”的对象时出错,该对象在“文件[D:\Workspace\DataServices\Main\Source\DataServices\TestResults\2010-07-30 11_58_31\Out\Spring.xml”中定义]':对象初始化失败:在初始化对象“DataLayer.DataServices”的属性“构造函数参数”期间,无法将托管列表元素“DataLayer.DataServices.IGetAccountMessage”从 [System.String] 转换为 [DataLayer.DataServices.IGetAccount]。 IDataService'。您是否注册了合适的类型转换器?
任何帮助表示赞赏。谢谢
I am trying to inject an IList into a constructor and want to know if this is possible and if so could someone enlightern me? The fact its asking for a type converter makes me think I can't do it.
I tried....
<object name="DataLayer.DataServices.IGetAccountDatabase" type="DataServices.LinqToEntities.EntityDataModel, DataServices.LinqToEntities" singleton="false"></object>
<object name="DataLayer.DataServices.IGetAccountMessage" type="DataServices.VMX.VmxModel, DataServices.VMX" singleton="false"></object>
<object name="DataLayer.DataServices.IDataService" type="DataServices.NavigationModel, DataServices" singleton="false">
<constructor-arg>
<list element-type="DataLayer.DataServices.IGetAccount, DataLayer" >
<idref object="DataLayer.DataServices.IGetAccountMessage"/>
<idref object="DataLayer.DataServices.IGetAccountDatabase"/>
</list>
</constructor-arg>
</object>
Error creating object with name 'DataLayer.DataServices.IDataService' defined in 'file [D:\Workspace\DataServices\Main\Source\DataServices\TestResults\2010-07-30 11_58_31\Out\Spring.xml]' : Initialization of object failed : Unable to convert managed list element 'DataLayer.DataServices.IGetAccountMessage' from [System.String] into [DataLayer.DataServices.IGetAccount] during initialization of property 'constructor argument' for object 'DataLayer.DataServices.IDataService'. Do you have an appropriate type converter registered?
Any help appreciated. thnx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为,如果您使用
id
而不是name
指定对象,它应该可以工作(通常使用 id 更好)。idref
元素只能用于通过id引用对象。如果对象
DataLayer.DataServices.IDataService
和对象DataLayer.DataServices.IGetAccountMessage
和DataLayer.DataServices.IGetAccountDatabase
是同一 xml 文件的一部分,您还可以使用idref
的local
属性。然后,在解析 xml 文件时,甚至在解析依赖项之前,您会收到错误消息。I think that if you specify the objects with an
id
instead of aname
it should work (it is generally better to use id's). Theidref
element can only be used to refer to objects by id.If the object
DataLayer.DataServices.IDataService
and the objectsDataLayer.DataServices.IGetAccountMessage
andDataLayer.DataServices.IGetAccountDatabase
are part of the same xml file, you can also use thelocal
attribute ofidref
. Then you get an error when the xml file is parsed, even before the dependencies will be resolved.