[英]castle: register interface proxies by convention
I want to register multiple components implementing the dictionary adapter, but the AllTypes.From.. only picks class-types. 我想注册实现字典适配器的多个组件,但是AllTypes.From ..只选择类类型。 I want to do something like this:
我想做这样的事情:
container.Register(AllTypes.FromAssemblyContaining<IFooSettings>()
.Where(type => type.IsInterface)
.Configure(component =>
component.UsingFactoryMethod((kernel, model, creationContext) => new DictionaryAdapterFactory().GetAdapter(creationContext.RequestedType, ConfigurationManager.AppSettings))));
Now I can't seem to be able to create my own version of "AllTypes" since the FromTypesDescriptor ctor is internal. 现在,由于FromTypesDescriptor ctor是内部的,因此我似乎无法创建自己的“ AllTypes”版本。 Any ideas how I can accomplish this?
有什么想法我可以做到这一点吗?
I do something like this 我做这样的事情
container.Register(
AllTypes
.FromThisAssembly()
.Pick()
.WithService.DefaultInterface()
.Configure(r => r.LifeStyle.Transient));
This registers components based on a matching interface and class name. 这根据匹配的接口和类名称注册组件。
So if I ask Castle for an interface called IFooSettings
then Castle will by default return the class FooSettings
. 因此,如果我要求Castle提供一个名为
IFooSettings
的接口,则Castle默认情况下将返回FooSettings
类。
There are a series of rules you can use for registration and you can see them here . 您可以使用一系列规则进行注册,您可以在此处查看它们。 It's does not recommend using the Factory method you are using in your example.
不建议您在示例中使用Factory方法。
This now works in Castle 3.3.0: 现在可以在Castle 3.3.0中使用:
var dictionaryAdapterFactory = new DictionaryAdapterFactory();
container.Register(
Types.FromThisAssembly().Where(t => t.Name.EndsWith("Settings") && t.IsInterface)
.Configure(component => component.UsingFactoryMethod((kernel, model, creationContext) => dictionaryAdapterFactory.GetAdapter(creationContext.RequestedType, ConfigurationManager.AppSettings))));
You have to use "Types" which also picks up interfaces 您必须使用“类型”,它也要拾取接口
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.