< idref>的Spring.NET问题在配置中标记 [英] Spring.NET problem with <idref> tag in config

查看:95
本文介绍了< idref>的Spring.NET问题在配置中标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据Spring.NET框架随附的帮助文件,您可以通过使用"idref"标记和"local"属性来注入在本地文件中定义的依赖项.

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>

创建上下文'spring.root'时出错:创建在文件[C:\ Test \ TestApp \ bin \ Debug \ my.config.xml]中定义的名称为'theClientObject'的对象时出错:通过构造函数参数表示的不满足的依赖性索引0类型为[TestClassLibrary.TargetObject]的对象:无法将构造函数参数值[theTargetObject]转换为所需的类型[TestClassLibrary.TargetObject]:无法将类型[System.String]的属性值转换为所需的属性[TestClassLibrary.TargetObject]类型".

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

推荐答案

我猜gef正确,但是在粘贴代码段时不小心将其混合了.您正在寻找

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>

为此的简写形式是:

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

hth, 埃里希

这篇关于&lt; idref&gt;的Spring.NET问题在配置中标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆