开发者

Convert Castle Windsor xml config to C# code

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 configuratio开发者_C百科n


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜