Add foundation

This commit is contained in:
TheXamlGuy
2024-04-13 11:29:32 +01:00
parent 6f31aa8513
commit 053d8a851e
264 changed files with 3428 additions and 4683 deletions
@@ -0,0 +1,25 @@
namespace Toolkit.Foundation;
public class NotificationHandlerWrapper<TNotification>(INotificationHandler<TNotification> handler,
IEnumerable<IPipelineBehavior<TNotification>> pipelineBehaviours)
where TNotification : INotification
{
private readonly IEnumerable<IPipelineBehavior<TNotification>> pipelineBehaviours =
pipelineBehaviours.Reverse();
public async Task Handle(TNotification notification,
CancellationToken cancellationToken)
{
NotificationHandlerDelegate<TNotification> currentHandler = handler.Handle;
foreach (IPipelineBehavior<TNotification> behavior in pipelineBehaviours)
{
NotificationHandlerDelegate<TNotification> previousHandler = currentHandler;
currentHandler = async (args, token) =>
{
await behavior.Handle(args, previousHandler, token);
};
}
await currentHandler(notification, cancellationToken);
}
}