Spring.NET问题 配置中的标签

发布于 2024-07-09 11:34:43 字数 835 浏览 13 评论 0原文

根据 Spring.NET 框架附带的帮助文件,您可以使用“idref”标签和“local”属性来注入本地文件中定义的依赖项。

我一直在尝试这样做,但没有成功,希望有人有经验可以帮助我。

下面是配置中的一个片段,我将其作为构造函数参数传递,但我也尝试将其设置为属性。 两种方法似乎都会产生相同的错误。

<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]。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

柒夜笙歌凉 2024-07-16 11:34:43

我猜 gef 的方向是正确的,但在粘贴代码片段时意外地混淆了它。您正在寻找 ; 元素

<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,
埃里希

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文