Retrieve GdPicture license key via MediatR from database

Refactored LicenseManager registration to fetch the GdPicture license key from the database using MediatR and ReadThirdPartyModuleLicenseQuery, instead of reading from configuration. Updated using statements accordingly.
This commit is contained in:
2026-04-14 13:25:07 +02:00
parent 2c8ae23203
commit c64c63925e

View File

@@ -1,6 +1,8 @@
using EnvelopeGenerator.Application.ThirdPartyModules.Queries;
using EnvelopeGenerator.ServiceHost.Jobs;
using EnvelopeGenerator.ServiceHost.Jobs.FinalizeDocument;
using GdPicture14;
using MediatR;
using Microsoft.Extensions.Options;
namespace EnvelopeGenerator.ServiceHost.Extensions;
@@ -26,12 +28,14 @@ public static class DependencyInjection
//TODO: Check lifetime of services. They might be singleton or scoped.
services.AddTransient<GdViewer>();
// Add LicenseManager
// Add LicenseManager license key is read from DB via MediatR
services.AddTransient(provider =>
{
var options = provider.GetRequiredService<IOptions<WorkerOptions>>().Value;
using var scope = provider.CreateScope();
var mediator = scope.ServiceProvider.GetRequiredService<IMediator>();
var licenseKey = mediator.Send(new ReadThirdPartyModuleLicenseQuery { Name = "GdPicture" }).GetAwaiter().GetResult();
var licenseManager = new LicenseManager();
licenseManager.RegisterKEY(options.GdPictureLicenseKey);
licenseManager.RegisterKEY(licenseKey);
return licenseManager;
});
services.AddTransient<AnnotationManager>();