[英]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.