Spring.NET problem with <idref> tag in config

一世执手 提交于 2019-12-24 11:25:05

问题


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 ''.


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/269845/spring-net-problem-with-idref-tag-in-config

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!