feat(GdPictureOptions): Created to configure parameters related to GdPicture.

- Configure the GdPicture license key via a third-party module entity.
This commit is contained in:
2025-11-03 15:36:11 +01:00
parent 23d4b2f31e
commit 187f4a42fc
5 changed files with 30 additions and 2 deletions

View File

@@ -1,7 +1,11 @@
using EnvelopeGenerator.Application.ThirdPartyModules.Queries;
using EnvelopeGenerator.DependencyInjection;
using EnvelopeGenerator.Finalizer;
using EnvelopeGenerator.Finalizer.Models;
using EnvelopeGenerator.Infrastructure;
using MediatR;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using Serilog;
// Load Serilog from appsettings.json
@@ -61,7 +65,20 @@ try
);
#endregion Add DB Context, EG Inf. and Services
builder.Services.AddOptions<GdPictureOptions>()
.Configure((GdPictureOptions opt, IServiceProvider sp) =>
{
var licenseKey = "GDPICTURE";
using var scope = sp.CreateScope();
var mediator = scope.ServiceProvider.GetRequiredService<IMediator>();
opt.License = mediator.ReadThirdPartyModuleLicenseAsync(licenseKey).GetAwaiter().GetResult()
?? throw new InvalidOperationException($"License record not found for key: {licenseKey}");
});
var host = builder.Build();
var licence = host.Services.GetRequiredService<IOptions<GdPictureOptions>>().Value;
host.Run();
Log.Information("The worker was stopped.");