refactor: add conditional PDFBurner and GdPicture service registration

This commit is contained in:
tekh 2025-11-10 13:43:44 +01:00
parent d2e8f1fc5e
commit 86c0a65540

View File

@ -24,9 +24,10 @@ public static class DependencyInjection
/// </summary> /// </summary>
/// <param name="services"></param> /// <param name="services"></param>
/// <param name="config"></param> /// <param name="config"></param>
/// <param name="usePdfBurner"></param>
/// <returns></returns> /// <returns></returns>
[Obsolete("Use MediatR")] [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 //Inject CRUD Service and repositoriesad
services.TryAddScoped<IConfigService, ConfigService>(); services.TryAddScoped<IConfigService, ConfigService>();
@ -50,6 +51,9 @@ public static class DependencyInjection
services.Configure<MailParams>(config.GetSection(nameof(MailParams))); services.Configure<MailParams>(config.GetSection(nameof(MailParams)));
services.Configure<AuthenticatorParams>(config.GetSection(nameof(AuthenticatorParams))); services.Configure<AuthenticatorParams>(config.GetSection(nameof(AuthenticatorParams)));
services.Configure<TotpSmsParams>(config.GetSection(nameof(TotpSmsParams))); services.Configure<TotpSmsParams>(config.GetSection(nameof(TotpSmsParams)));
if (usePdfBurner)
{
services.Configure<PDFBurnerParams>(config.GetSection(nameof(PDFBurnerParams))); services.Configure<PDFBurnerParams>(config.GetSection(nameof(PDFBurnerParams)));
services.AddOptions<GdPictureParams>() services.AddOptions<GdPictureParams>()
.Configure((GdPictureParams opt, IServiceProvider provider) => .Configure((GdPictureParams opt, IServiceProvider provider) =>
@ -58,17 +62,20 @@ public static class DependencyInjection
?? provider.GetRequiredService<IMediator>().ReadThirdPartyModuleLicenseAsync("GDPICTURE").GetAwaiter().GetResult() ?? provider.GetRequiredService<IMediator>().ReadThirdPartyModuleLicenseAsync("GDPICTURE").GetAwaiter().GetResult()
?? throw new InvalidOperationException($"License record not found for key: {"GDPICTURE"}"); ?? throw new InvalidOperationException($"License record not found for key: {"GDPICTURE"}");
}); });
services.AddSingleton(provider => { services.AddSingleton(provider =>
{
var license = provider.GetRequiredService<IOptions<GdPictureParams>>().Value.License; var license = provider.GetRequiredService<IOptions<GdPictureParams>>().Value.License;
var licenseManager = new LicenseManager(); var licenseManager = new LicenseManager();
licenseManager.RegisterKEY(license); licenseManager.RegisterKEY(license);
return licenseManager; return licenseManager;
}); });
services.AddTransient(provider => { services.AddTransient(provider =>
{
// Ensure LicenseManager is resolved so that its constructor is called // Ensure LicenseManager is resolved so that its constructor is called
_ = provider.GetRequiredService<LicenseManager>(); _ = provider.GetRequiredService<LicenseManager>();
return new AnnotationManager(); return new AnnotationManager();
}); });
}
services.AddHttpClientService<GtxMessagingParams>(config.GetSection(nameof(GtxMessagingParams))); services.AddHttpClientService<GtxMessagingParams>(config.GetSection(nameof(GtxMessagingParams)));
services.TryAddSingleton<ISmsSender, GTXSmsSender>(); services.TryAddSingleton<ISmsSender, GTXSmsSender>();