Spring .NET problem with <idref> tag in config
According to the help file that comes with the Spring.NET framework, you can inject a dependency defined in a local file using the idref tag along with the "local" attribute.
I tried to do this with no success and hoped someone had some experience to help me.
Below I have a snippet from config where I pass it as a constructor argument, but I tried to set it as a property. Both methods seem to give the same error.
<object id="theTargetObject" type="TestClassLibrary.TargetObject, TestClassLibrary"/>
<object id="theClientObject" type="TestClassLibrary.ClientObject, TestClassLibrary">
<constructor-arg name="myClass">
<idref local="theTargetObject"/>
</constructor-arg>
</object>
Failed to create context 'spring.root': Failed to create object named 'theClientObject' defined in 'file [C: \ Test \ TestApp \ bin \ Debug \ my.config.xml]': Unsatisfactory dependency expressed via constructor with index 0 of type [TestClassLibrary.TargetObject]: Could not convert value of constructor argument [theTargetObject] to required type [TestClassLibrary.TargetObject]: Unable to convert property value of type [System.String] to required type [TestClassLibrary.TargetObject] for property ''.
I think gef was on the right track, but accidentally mixed it up while pasting the snippet. You're looking for the <ref> element :
<object id="theTargetObject" type="TestClassLibrary.TargetObject, TestClassLibrary"/>
<object id="theClientObject" type="TestClassLibrary.ClientObject, TestClassLibrary">
<property name="myClass">
<ref local="theTargetObject"/>
</property>
shorthand for this:
<object id="theClientObject" type="TestClassLibrary.ClientObject, TestClassLibrary">
<property name="myClass ref="theTargetObject"/>
NTN, Erich
source to share