如何自动向 Castle Windsor 注册开放式通用接口?
How to automatically register open generic interface with Castle Windsor?
我需要将我的开放通用接口自动注册到它的实现 classes
我的界面类似于 IIntegrationEventHandler
public interface IIntegrationEventHandler<in TIntegrationEvent>
where TIntegrationEvent : BaseIntegrationEvent
{
Task HandleAsync(TIntegrationEvent @event);
}
我的处理程序将是这样的
public class EmployeeEventsHandler : IIntegrationEventHandler<EmployeeUserCreated>
{
public async Task HandleAsync(EmployeeUserCreated @event)
{
throw new NotImplementedException();
}
}
在 Castle Windsor 中是否有任何通用的方法来进行此类注册而无需手动对每个处理程序进行注册,我搜索了很多但什么也没有请注意我没有基本处理程序class, 只有通用接口和实现 classes
按照惯例注册应该在这里工作:
var container = new WindsorContainer();
container.Register(
Classes.FromAssemblyNamed("YourHandlersAssemblyName")
.BasedOn(typeof(IIntegrationEventHandler<>))
.WithServiceFirstInterface());
var handler = container.Resolve<IIntegrationEventHandler<EmployeeUserCreated>>();
我需要将我的开放通用接口自动注册到它的实现 classes 我的界面类似于 IIntegrationEventHandler
public interface IIntegrationEventHandler<in TIntegrationEvent>
where TIntegrationEvent : BaseIntegrationEvent
{
Task HandleAsync(TIntegrationEvent @event);
}
我的处理程序将是这样的
public class EmployeeEventsHandler : IIntegrationEventHandler<EmployeeUserCreated>
{
public async Task HandleAsync(EmployeeUserCreated @event)
{
throw new NotImplementedException();
}
}
在 Castle Windsor 中是否有任何通用的方法来进行此类注册而无需手动对每个处理程序进行注册,我搜索了很多但什么也没有请注意我没有基本处理程序class, 只有通用接口和实现 classes
按照惯例注册应该在这里工作:
var container = new WindsorContainer();
container.Register(
Classes.FromAssemblyNamed("YourHandlersAssemblyName")
.BasedOn(typeof(IIntegrationEventHandler<>))
.WithServiceFirstInterface());
var handler = container.Resolve<IIntegrationEventHandler<EmployeeUserCreated>>();