本文介绍了将Castle Windsor xml配置转换为C#代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想转换这样的东西:
<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>
这样的代码:
Container.AddComponentWithProperties<Consumer>(Container.ResolveAll<IService>());
任何人都知道如何执行此操作。
Anyone have any ideas how to do this.
注意:
我正在尝试执行以下内容:这篇文章,但不使用XML:
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
推荐答案
container.Register(Component.For<Consumer>()
.DynamicParameters((kernel, parameters) =>
parameters["services"] = new Dictionary<string, IService> {
{"one", kernel.Resolve<IService>("service1")},
{"two", kernel.Resolve<IService>("service2")},
}
));
请参见供参考。
这篇关于将Castle Windsor xml配置转换为C#代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!