tags:

views:

49

answers:

1

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

A: 

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.

Ronald Wildenberg
Thanks very much I have got this working and you pointed me in the right direction. Basically it appears that the idref element passes the name of the obejct as a string whereas the ref element passes the object, hence the error I was getting. While looking at the idref element and the local attribute I came across this post... http://stackoverflow.com/questions/269845/spring-net-problem-with-idref-tag-in-config