using EnvelopeGenerator.Application.Common.Interfaces;
using EnvelopeGenerator.Application.DocReceiverElements.Commands;
using MediatR;
using Microsoft.Extensions.Logging;
namespace EnvelopeGenerator.Application.DocReceiverElements.Behaviors;
///
///
///
public class TriggerFinalizationWorkerBehavior(ILogger Logger, IEnvelopeFinalizationTrigger? Trigger = null) : IPipelineBehavior
{
///
///
///
///
///
///
///
///
public async Task Handle(SigningCommand request, RequestHandlerDelegate next, CancellationToken cancellationToken)
{
if(Trigger != null)
try
{
await Trigger.TriggerAsync(cancellationToken);
}
catch (Exception ex)
{
// Log the exception or handle it as needed
Logger.LogError(ex, "Error triggering finalization worker");
}
return await next(cancellationToken);
}
}