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
I think that if you specify the objects with an
idinstead of anameit should work (it is generally better to use id’s). Theidrefelement can only be used to refer to objects by id.If the object
DataLayer.DataServices.IDataServiceand the objectsDataLayer.DataServices.IGetAccountMessageandDataLayer.DataServices.IGetAccountDatabaseare part of the same xml file, you can also use thelocalattribute ofidref. Then you get an error when the xml file is parsed, even before the dependencies will be resolved.