1

I want to convert something like this:

<components>
    <component id=""service1"" service=""WindsorTests.IService, MyAssembly""         type=""WindsorTests.Service1, MyAssembly""/>
    <component id=""service2"" service=""WindsorTests.IService, MyAssembly"" type=""WindsorTests.Service2, MyAssembly""/>
    <component id=""consumer"" type=""WindsorTests.Consumer, MyAssembly"">
        <parameters>
            <services>
                <dictionary>
                    <entry key=""one"">${service1}</entry>
                    <entry key=""two"">${service2}</entry>
                </dictionary>
            </services>
        </parameters>
    </component>
</components>

Into code like this:

Container.AddComponentWithProperties<Consumer>(Container.ResolveAll<IService>());

Anyone have any ideas how to do this.

Note:

I am trying to do something like what is described in this post, but without using XML: Windsor Castle :- Inject Dictionary of Interfaces via configuration

Community
  • 1
  • 1
JasonRShaver
  • 4,344
  • 3
  • 32
  • 39
  • What does Consumer look like? I'm not quite sure I understand whether the services you would like to inject are a list, a params array, a dictionary or something else... – Mark Seemann Jan 30 '10 at 09:55

1 Answers1

2
container.Register(Component.For<Consumer>()
               .DynamicParameters((kernel, parameters) => 
                   parameters["services"] = new Dictionary<string, IService> {
                     {"one", kernel.Resolve<IService>("service1")},
                     {"two", kernel.Resolve<IService>("service2")},
                   }
               ));

See the fluent API wiki for reference.

Mauricio Scheffer
  • 98,863
  • 23
  • 192
  • 275
  • Worked great, I needed to upgrade to the newest version of Castle Windsor for this to work (DynamicParameters was not in the version I had). – JasonRShaver Feb 03 '10 at 20:14
  • In addition, the fluent API version of the 'normal' register is: Container.Register(Component.For().ImplementedBy< WindsorTests.Service1 >().Named("service1")); – JasonRShaver Feb 03 '10 at 20:15