1

According to the help file that comes with the Spring.NET framework, you can inject a dependancy defined in the local file by using an 'idref' tag along with a 'local' attribute.

I have been trying to do this with no success and was hoping someone had the experience to help me out.

Below I have a snippet from the config where I am passing it as a constructor argument, but I have tried setting it as a property as well. Both methods seem to yield 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>

Error creating context 'spring.root': Error creating object with name 'theClientObject' defined in 'file [C:\Test\TestApp\bin\Debug\my.config.xml]' : Unsatisfied dependency expressed through constructor argument with index 0 of type [TestClassLibrary.TargetObject] : Could not convert constructor argument value [theTargetObject] to required type [TestClassLibrary.TargetObject] : Cannot convert property value of type [System.String] to required type [TestClassLibrary.TargetObject] for property ''.

2 Answers2

2

I guess gef was on the right way but accidentially mixed it up when pasting the snippet.You are 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>

the shorthand notation for this is:

<object id="theClientObject" type="TestClassLibrary.ClientObject, TestClassLibrary">
     <property name="myClass ref="theTargetObject"/>

hth, Erich

Erich Eichinger
  • 1,898
  • 17
  • 15
  • Oops, well spotted - I should have used this - http://www.springframework.net/docs/1.2.0-RC1/reference/html/vsnet.html#vsnet-config-section :) – gef Jan 04 '09 at 15:43
1

Please view the post http://forum.springsource.org/showthread.php?t=14211

intangible02
  • 993
  • 1
  • 9
  • 19