views:

120

answers:

1

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,

A: 

If you have components with type Mapping or OtherType registered in the container, Windsor will inject them in your optional dependencies. 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.

If you want to avoid injecting some optional dependencies, see this question.

Mauricio Scheffer
I still want the other optional dependencies to be injectable from configuration, but not based only on type.. only when the name of the parameter in configuration matches..Some applications will just intialize one property, while others will intialize more... Any property that is no explictily intialized in configuration should remain null.
Damian