namespace Toolkit.Foundation; public class NotificationHandlerWrapper(INotificationHandler handler, IEnumerable> pipelineBehaviours) { private readonly IEnumerable> pipelineBehaviours = pipelineBehaviours.Reverse(); public async Task Handle(TMessage message) { NotificationHandlerDelegate currentHandler = handler.Handle; foreach (IPipelineBehaviour behaviour in pipelineBehaviours) { NotificationHandlerDelegate previousHandler = currentHandler; currentHandler = async (args) => { await behaviour.Handle(args, previousHandler); }; } await currentHandler(message); } }