From ecd695ad370fcc7535ec84925b2cb6bb45083058 Mon Sep 17 00:00:00 2001 From: TekH Date: Tue, 9 Jun 2026 18:33:27 +0200 Subject: [PATCH] Add MediatR pipeline behaviors for SignCommand Introduced MediatR to the project by adding the `using MediatR;` directive in `DependencyInjection.cs`. Registered pipeline behaviors for the `Signature.Commands.SignCommand` to enforce a structured execution order: 1. AnnotationBehavior: Saves annotations. 2. DocStatusBehavior: Creates document status. 3. HistoryBehavior: Records history. 4. SendSignedMailBehavior: Sends notification email (executes last). These changes improve the command handling pipeline by ensuring sequential and reliable execution of behaviors. --- .../DependencyInjection.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/EnvelopeGenerator.Application/DependencyInjection.cs b/EnvelopeGenerator.Application/DependencyInjection.cs index ef9838a1..316724ad 100644 --- a/EnvelopeGenerator.Application/DependencyInjection.cs +++ b/EnvelopeGenerator.Application/DependencyInjection.cs @@ -7,6 +7,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using QRCoder; using System.Reflection; +using MediatR; namespace EnvelopeGenerator.Application; @@ -56,6 +57,19 @@ public static class DependencyInjection services.AddMediatR(cfg => { cfg.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()); + + // Register SignCommand pipeline behaviors in execution order + // 1. AnnotationBehavior - Saves annotations (executes first) + cfg.AddBehavior, Signature.Behaviors.AnnotationBehavior>(); + + // 2. DocStatusBehavior - Creates document status (executes second) + cfg.AddBehavior, Signature.Behaviors.DocStatusBehavior>(); + + // 3. HistoryBehavior - Records history (executes third) + cfg.AddBehavior, Signature.Behaviors.HistoryBehavior>(); + + // 4. SendSignedMailBehavior - Sends notification email (executes LAST, only if all previous succeed) + cfg.AddBehavior, Signature.Behaviors.SendSignedMailBehavior>(); }); return services;