From 86c0a65540af27c6d5b869ee90d6f5744237df61 Mon Sep 17 00:00:00 2001 From: TekH Date: Mon, 10 Nov 2025 13:43:44 +0100 Subject: [PATCH] refactor: add conditional PDFBurner and GdPicture service registration --- .../DependencyInjection.cs | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/EnvelopeGenerator.Application/DependencyInjection.cs b/EnvelopeGenerator.Application/DependencyInjection.cs index 0d9116be..9e0042ef 100644 --- a/EnvelopeGenerator.Application/DependencyInjection.cs +++ b/EnvelopeGenerator.Application/DependencyInjection.cs @@ -24,9 +24,10 @@ public static class DependencyInjection /// /// /// + /// /// [Obsolete("Use MediatR")] - public static IServiceCollection AddEnvelopeGeneratorServices(this IServiceCollection services, IConfiguration config) + public static IServiceCollection AddEnvelopeGeneratorServices(this IServiceCollection services, IConfiguration config, bool usePdfBurner = false) { //Inject CRUD Service and repositoriesad services.TryAddScoped(); @@ -50,25 +51,31 @@ public static class DependencyInjection services.Configure(config.GetSection(nameof(MailParams))); services.Configure(config.GetSection(nameof(AuthenticatorParams))); services.Configure(config.GetSection(nameof(TotpSmsParams))); - services.Configure(config.GetSection(nameof(PDFBurnerParams))); - services.AddOptions() - .Configure((GdPictureParams opt, IServiceProvider provider) => + + if (usePdfBurner) { - 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.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();