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; namespace EnvelopeGenerator.Application; /// /// Extensions method for dependency injection /// public static class DependencyInjection { /// /// Adds all required services for envelope generator application /// /// /// /// [Obsolete("Use MediatR")] public static IServiceCollection AddEnvelopeGeneratorServices(this IServiceCollection services, IConfiguration config) { //Inject CRUD Service and repositoriesad services.TryAddScoped(); services.TryAddScoped(); services.TryAddScoped(); services.TryAddScoped(); services.TryAddScoped(); services.TryAddScoped(); services.TryAddScoped(); services.TryAddScoped(); services.TryAddScoped(); services.TryAddScoped(); services.TryAddScoped(); services.TryAddScoped(); //Auto mapping profiles services.AddAutoMapper(Assembly.GetExecutingAssembly()); services.AddAutoMapper(typeof(DigitalData.UserManager.Application.DIExtensions)); services.Configure(config.GetSection(nameof(DispatcherParams))); services.Configure(config.GetSection(nameof(MailParams))); services.Configure(config.GetSection(nameof(AuthenticatorParams))); services.Configure(config.GetSection(nameof(TotpSmsParams))); services.AddHttpClientService(config.GetSection(nameof(GtxMessagingParams))); services.TryAddSingleton(); services.TryAddSingleton(); services.TryAddSingleton(); services.TryAddSingleton(); 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; } }