Recent addition of ScanForTypes attribute is really nice improvement!
I was wondering whether you're willing to support specyfing methods for Handler property that are implemented in other assembly?
This might be usefull for sharing some common registration methods and avoid duplication.
Sample usecase with modular application where each module will register it's own handlers and decorators:
[ScanForTypes(
AssignableTo = typeof(ICommandHandler<>),
Handler = nameof(Extensions.DecorateCommandHandler)
)]
[ScanForTypes(
AssignableTo = typeof(ICommandHandler<,>),
Handler = nameof(Extensions.DecorateCommandHandlerWithResponse)
)]
[ScanForTypes(
AssignableTo = typeof(IEventHandler<>),
Handler = nameof(Extensions.DecorateIntegrationEventHandler)
)]
private static partial IServiceCollection AddTransactionalProcessing(
this IServiceCollection services
);
[ScanForTypes(
AssignableTo = typeof(ICommandHandler<>),
Handler = nameof(Extensions.DecorateCommandHandler)
)]
[ScanForTypes(
AssignableTo = typeof(ICommandHandler<,>),
Handler = nameof(Extensions.DecorateCommandHandlerWithResponse)
)]
[ScanForTypes(
AssignableTo = typeof(IEventHandler<>),
Handler = nameof(Extensions.DecorateIntegrationEventHandler)
)]
private static partial IServiceCollection AddTransactionalProcessing(
this IServiceCollection services
);
- Common Module (referenced by First and Second one)
public static class Extensions
{
public static void DecorateCommandHandler<THandler, TRequest>(IServiceCollection services)
where THandler : class, ICommandHandler<TRequest>
where TRequest : class, ICommand =>
services.Decorate<IRequestHandler<TRequest>, CommandTransactionDecorator<TRequest>>();
public static void DecorateCommandHandlerWithResponse<THandler, TRequest, TResult>(
IServiceCollection services
)
where THandler : class, ICommandHandler<TRequest, TResult>
where TRequest : class, ICommand<TResult> =>
services.Decorate<
IRequestHandler<TRequest, TResult>,
CommandWithResponseTransactionDecorator<TRequest, TResult>
>();
public static void DecorateIntegrationEventHandler<THandler, TEvent>(
IServiceCollection services
)
where THandler : class, IEventHandler<TEvent>
where TEvent : BaseIntegrationEvent =>
services.Decorate<
INotificationHandler<TEvent>,
IntegrationEventTransactionDecorator<TEvent>
>();
}
Recent addition of
ScanForTypesattribute is really nice improvement!I was wondering whether you're willing to support specyfing methods for
Handlerproperty that are implemented in other assembly?This might be usefull for sharing some common registration methods and avoid duplication.
Sample usecase with modular application where each module will register it's own handlers and decorators: