简体   繁体   English

温莎城堡集装箱无法正确布线

[英]castle windsor container not wiring properties correctly

I have a class that i want to instantiate thru castle in configuration. 我有一堂课,我想通过配置实例化城堡。

public class MyMappings : IMappings
{
    Mapping FirstMapping { get; set; }
    Mapping SecondMapping { get; set; }
    OtherType ThirdMapping { get; set; }
    OtherType FourthMapping { get; set; }
    Mapping FifthMapping { get; set; }
    OtherType SixMapping { get; set; }
}

In my configuration i have the following: 在我的配置中,我有以下内容:

< component id="mymappings" type="MyMappings, MyAssmebly" >
   < parameters>
       < firstMapping>${anothercomponentIDForCompomentOftypeMapping}< /firstMapping>
   < /parameters>
< /component>

The problem i am facing is that is assigning the same value to all properties of the same type, completly ignoring the name of the parameter. 我面临的问题是,将相同的值分配给相同类型的所有属性,而完全忽略参数的名称。 This properties are optional, i just want to initialize the value for one of them. 此属性是可选的,我只想初始化其中一个的值。

Thanks, 谢谢,

If you have components with type Mapping or OtherType registered in the container, Windsor will inject them in your optional dependencies. 如果您在容器中注册了类型为Mapping或OtherType的组件,Windsor会将它们注入到您的可选依赖项中。 What you did in your xml configuration is a service override, that is, you selected a specific component for a specific parameter, but that doesn't mean that other parameters will not be injected is a fitting component is available. 在xml配置中所做的是服务覆盖,即为特定参数选择了特定组件,但这并不意味着不会注入其他参数(如果有合适的组件)。

If you want to avoid injecting some optional dependencies, see this question . 如果要避免注入一些可选的依赖项,请参阅此问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM