Updated IEnvelopeFinalizationTrigger to support CancellationToken in TriggerAsync for improved cancellation handling. Introduced TriggerFinalizationWorkerBehavior to trigger finalization in the SigningCommand pipeline. Updated DependencyInjection to include the new behavior. Refactored EnvelopeFinalizationTrigger to align with interface changes and removed unused using directives.
102 lines
5.1 KiB
C#
102 lines
5.1 KiB
C#
using DigitalData.Core.Client;
|
|
using EnvelopeGenerator.Application.Common.Configurations;
|
|
using EnvelopeGenerator.Application.Common.Interfaces.Services;
|
|
using EnvelopeGenerator.Application.Services;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
|
using QRCoder;
|
|
using System.Reflection;
|
|
using MediatR;
|
|
using EnvelopeGenerator.Application.DocReceiverElements.Commands;
|
|
using EnvelopeGenerator.Application.DocReceiverElements.Behaviors;
|
|
using EnvelopeGenerator.Application.Common.Behaviors;
|
|
using FluentValidation;
|
|
using EnvelopeGenerator.Application.EnvelopeReceivers.Commands;
|
|
|
|
namespace EnvelopeGenerator.Application;
|
|
|
|
/// <summary>
|
|
/// Extensions method for dependency injection
|
|
/// </summary>
|
|
public static class DependencyInjection
|
|
{
|
|
/// <summary>
|
|
/// Adds all required services for envelope generator application
|
|
/// </summary>
|
|
/// <param name="services"></param>
|
|
/// <param name="config"></param>
|
|
/// <returns></returns>
|
|
[Obsolete("Use MediatR")]
|
|
public static IServiceCollection AddEnvelopeGeneratorServices(this IServiceCollection services, IConfiguration config)
|
|
{
|
|
//Inject CRUD Service and repositoriesad
|
|
services.TryAddScoped<IConfigService, ConfigService>();
|
|
services.TryAddScoped<IDocumentReceiverElementService, DocumentReceiverElementService>();
|
|
services.TryAddScoped<IEnvelopeDocumentService, EnvelopeDocumentService>();
|
|
services.TryAddScoped<IEnvelopeHistoryService, EnvelopeHistoryService>();
|
|
services.TryAddScoped<IDocumentStatusService, DocumentStatusService>();
|
|
services.TryAddScoped<IEmailTemplateService, EmailTemplateService>();
|
|
services.TryAddScoped<IEnvelopeService, EnvelopeService>();
|
|
services.TryAddScoped<IEnvelopeDocumentService, EnvelopeDocumentService>();
|
|
services.TryAddScoped<IEnvelopeReceiverService, EnvelopeReceiverService>();
|
|
services.TryAddScoped<IEnvelopeTypeService, EnvelopeTypeService>();
|
|
services.TryAddScoped<IReceiverService, ReceiverService>();
|
|
services.TryAddScoped<IEnvelopeReceiverReadOnlyService, EnvelopeReceiverReadOnlyService>();
|
|
|
|
//Auto mapping profiles
|
|
services.AddAutoMapper(
|
|
_ => { },
|
|
Assembly.GetExecutingAssembly(),
|
|
typeof(DigitalData.UserManager.Application.DIExtensions).Assembly);
|
|
|
|
services.Configure<DispatcherParams>(config.GetSection(nameof(DispatcherParams)));
|
|
services.Configure<MailParams>(config.GetSection(nameof(MailParams)));
|
|
services.Configure<SignatureFieldParams>(config.GetSection(nameof(SignatureFieldParams)));
|
|
services.Configure<AuthenticatorParams>(config.GetSection(nameof(AuthenticatorParams)));
|
|
services.Configure<TotpSmsParams>(config.GetSection(nameof(TotpSmsParams)));
|
|
services.Configure<ESignParams>(config.GetSection(nameof(ESignParams)));
|
|
services.Configure<SendAccessCodeParams>(config.GetSection(nameof(SendAccessCodeParams)));
|
|
|
|
services.AddHttpClientService<GtxMessagingParams>(config.GetSection(nameof(GtxMessagingParams)));
|
|
services.TryAddScoped<ISmsSender, GTXSmsSender>(); // Changed: Singleton → Scoped
|
|
services.TryAddScoped<IEnvelopeSmsHandler, EnvelopeSmsHandler>(); // Changed: Singleton → Scoped
|
|
services.TryAddSingleton<IAuthenticator, Authenticator>();
|
|
services.TryAddSingleton<QRCodeGenerator>();
|
|
|
|
services.AddMediatR(cfg =>
|
|
{
|
|
cfg.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly());
|
|
|
|
// Generic request validation
|
|
cfg.AddOpenBehavior(typeof(ValidationBehavior<,>));
|
|
|
|
// Register SignCommand pipeline behaviors in execution order
|
|
// 0. EnvelopeReceiverResolutionBehavior - Resolves EnvelopeReceiver from query parameters (executes FIRST)
|
|
cfg.AddBehavior<IPipelineBehavior<SigningCommand, Unit>, EnvelopeReceiverResolutionBehavior>();
|
|
|
|
// 1. AnnotationBehavior - Saves annotations (executes second)
|
|
cfg.AddBehavior<IPipelineBehavior<SigningCommand, Unit>, SaveSignatureBehavior>();
|
|
|
|
// 2. AnnotationBehavior - Saves annotations for legacy web flow
|
|
cfg.AddBehavior<IPipelineBehavior<SigningCommand, Unit>, AnnotationBehavior>();
|
|
|
|
// 3. DocStatusBehavior - Creates document status
|
|
cfg.AddBehavior<IPipelineBehavior<SigningCommand, Unit>, DocStatusBehavior>();
|
|
|
|
// 4. HistoryBehavior - Records history
|
|
cfg.AddBehavior<IPipelineBehavior<SigningCommand, Unit>, HistoryBehavior>();
|
|
|
|
// 5. SendSignedMailBehavior - Sends notification email (executes LAST)
|
|
cfg.AddBehavior<IPipelineBehavior<SigningCommand, Unit>, SendSignedMailBehavior>();
|
|
|
|
// 6. TriggerFinalizationWorkerBehavior - Triggers the finalization worker (executes LAST)
|
|
cfg.AddBehavior<IPipelineBehavior<SigningCommand, Unit>, TriggerFinalizationWorkerBehavior>();
|
|
});
|
|
|
|
services.AddValidatorsFromAssembly(Assembly.GetExecutingAssembly());
|
|
|
|
return services;
|
|
}
|
|
}
|