This commit is contained in:
TheXamlGuy
2024-04-26 22:27:31 +01:00
parent d799eab511
commit 9f90ef693d
39 changed files with 236 additions and 211 deletions
@@ -1,25 +1,24 @@
namespace Toolkit.Foundation;
public class NotificationHandlerWrapper<TNotification>(INotificationHandler<TNotification> handler,
IEnumerable<IPipelineBehavior<TNotification>> pipelineBehaviours)
where TNotification : INotification
public class NotificationHandlerWrapper<TMessage>(INotificationHandler<TMessage> handler,
IEnumerable<IPipelineBehaviour<TMessage>> pipelineBehaviours)
{
private readonly IEnumerable<IPipelineBehavior<TNotification>> pipelineBehaviours =
private readonly IEnumerable<IPipelineBehaviour<TMessage>> pipelineBehaviours =
pipelineBehaviours.Reverse();
public async Task Handle(TNotification notification,
public async Task Handle(TMessage message,
CancellationToken cancellationToken)
{
NotificationHandlerDelegate<TNotification> currentHandler = handler.Handle;
foreach (IPipelineBehavior<TNotification> behavior in pipelineBehaviours)
NotificationHandlerDelegate<TMessage> currentHandler = handler.Handle;
foreach (IPipelineBehaviour<TMessage> behaviour in pipelineBehaviours)
{
NotificationHandlerDelegate<TNotification> previousHandler = currentHandler;
NotificationHandlerDelegate<TMessage> previousHandler = currentHandler;
currentHandler = async (args, token) =>
{
await behavior.Handle(args, previousHandler, token);
await behaviour.Handle(args, previousHandler, token);
};
}
await currentHandler(notification, cancellationToken);
await currentHandler(message, cancellationToken);
}
}