using DigitalData.Core.Client; using EnvelopeGenerator.Application.Common.Configurations; using EnvelopeGenerator.Application.Common.Interfaces.Services; using EnvelopeGenerator.Application.Services; using EnvelopeGenerator.Application.ThirdPartyModules.Queries; using MediatR; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Options; using QRCoder; using System.Reflection; using GdPicture14; using EnvelopeGenerator.Application.Pdf.Behaviors; 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, bool usePdfBurner = false) { //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))); if (usePdfBurner) { services.Configure(config.GetSection(nameof(PDFBurnerParams))); services.AddOptions() .Configure((GdPictureParams opt, IServiceProvider provider) => { opt.License = config["GdPictureLicenseKey"] ?? provider.GetRequiredService().ReadThirdPartyModuleLicenseAsync("GDPICTURE").GetAwaiter().GetResult() ?? throw new InvalidOperationException($"License record not found for key: {"GDPICTURE"}"); }); services.AddSingleton(provider => { var license = provider.GetRequiredService>().Value.License; var licenseManager = new LicenseManager(); licenseManager.RegisterKEY(license); return licenseManager; }); services.AddTransient(provider => { // Ensure LicenseManager is resolved so that its constructor is called _ = provider.GetRequiredService(); return new AnnotationManager(); }); } services.AddHttpClientService(config.GetSection(nameof(GtxMessagingParams))); services.TryAddSingleton(); services.TryAddSingleton(); services.TryAddSingleton(); services.TryAddSingleton(); services.AddMediatR(cfg => { cfg.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()); cfg.AddOpenBehaviors(new Type[] { typeof(AddReportBehavior), typeof(SavePdfBehavior) }); }); // Add memory cache services.AddMemoryCache(); // Register mail services services.AddScoped(); return services; } }