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:
@@ -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.");
|
||||
|
||||
Reference in New Issue
Block a user