简体   繁体   English

如何自动注册Castle Windsor的开放式通用界面?

[英]How to automatically register open generic interface with Castle Windsor?

I need to automatically register my open generic interface to its implementation classes My interface is something like that IIntegrationEventHandler 我需要自动将我的开放通用接口注册到它的实现类我的接口类似于IIntegrationEventHandler

public interface IIntegrationEventHandler<in TIntegrationEvent> 
    where TIntegrationEvent : BaseIntegrationEvent
{
    Task HandleAsync(TIntegrationEvent @event);
}

My handlers will be something like that 我的处理程序就是这样的

    public class EmployeeEventsHandler : IIntegrationEventHandler<EmployeeUserCreated>
{
    public async Task HandleAsync(EmployeeUserCreated @event)
    {
        throw new NotImplementedException();
    }        
}

Is there any general way in Castle Windsor to do such registration without manually do it with every handler, i searched a lot but nothing note that i don't have a base handler class, only the generic interface and the implementation classes 有没有一般的方法在Castle Windsor做这样的注册而不用手动对每个处理程序进行,我搜索了很多但没有注意到我没有基本处理程序类,只有通用接口和实现类

Registration by conventions should work here: 按惯例注册应该在这里工作:

var container = new WindsorContainer();

container.Register(
    Classes.FromAssemblyNamed("YourHandlersAssemblyName")
    .BasedOn(typeof(IIntegrationEventHandler<>))
    .WithServiceFirstInterface());

var handler = container.Resolve<IIntegrationEventHandler<EmployeeUserCreated>>();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Castle Windsor中,如何为所有找到的通用类型的实现注册通用接口的许多实现之一? - In Castle Windsor, how to register ONE of many implementations of generic interface for ALL found implementations of generic type? Castle Windsor-开放通用接口的IoC注册? - Castle Windsor - IoC registration for open generic interfaces? 温莎城堡-如何将实现泛型接口的接口注册到具有泛型的类? - Castle Windsor - How can I register an interface that implements an interface with generics to a class with generics? 在Castle Windsor中,我可以注册一个Interface组件并获得实现的代理吗? - In Castle Windsor, can I register a Interface component and get a proxy of the implementation? 温莎城堡温莎登记册组成部分 - Castle Windsor Register Component by Convention 温莎城堡IoC,如何注册IBaseService <TObject> 到BaseService <TObject, TRepository> - Windsor Castle IoC, how to register IBaseService<TObject> to BaseService<TObject, TRepository> 多个接口注入城堡windsor - Multiple Interface injection with castle windsor 当还有专门的服务类型时,使用 Castle Windsor 的流畅接口在装饰器链中注册组件? - Using Castle Windsor's fluent interface to register components in a decorator chain, when there are also specialised service-types? 在Castle Windsor中使用泛型参数解析泛型 - Resolving a Generic with a Generic parameter in Castle Windsor Castle Windsor 解析 1 个接口的多个通用实现 - Castle Windsor Resolving Mutiple Generic Implementations of 1 Inteface
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM