Spring.NET - IList的构造函数参数

发布于 2024-09-11 23:33:41 字数 1281 浏览 5 评论 0原文

我正在尝试将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傾城如夢未必闌珊 2024-09-18 23:33:41

我认为,如果您使用 id 而不是 name 指定对象,它应该可以工作(通常使用 id 更好)。 idref 元素只能用于通过id引用对象。

如果对象 DataLayer.DataServices.IDataService 和对象 DataLayer.DataServices.IGetAccountMessageDataLayer.DataServices.IGetAccountDatabase 是同一 xml 文件的一部分,您还可以使用 idreflocal 属性。然后,在解析 xml 文件时,甚至在解析依赖项之前,您会收到错误消息。

I think that if you specify the objects with an id instead of a name it should work (it is generally better to use id's). The idref element can only be used to refer to objects by id.

If the object DataLayer.DataServices.IDataService and the objects DataLayer.DataServices.IGetAccountMessage and DataLayer.DataServices.IGetAccountDatabase are part of the same xml file, you can also use the local attribute of idref. Then you get an error when the xml file is parsed, even before the dependencies will be resolved.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文