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.
45 lines
1.8 KiB
C#
45 lines
1.8 KiB
C#
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;
|
||
|
||
public static class DependencyInjection
|
||
{
|
||
[Obsolete("Check obsoleted services")]
|
||
public static IServiceCollection AddFinalizeDocumentJob(this IServiceCollection services, IConfiguration configuration)
|
||
{
|
||
services.Configure<WorkerOptions>(configuration.GetSection("Worker"));
|
||
services.AddSingleton(provider =>
|
||
{
|
||
var options = provider.GetRequiredService<IOptions<WorkerOptions>>().Value;
|
||
var manager = new JobStateManager(options.InitialJobState);
|
||
return manager;
|
||
});
|
||
services.AddScoped<FinalizeDocumentJob>();
|
||
services.AddScoped<ActionService>();
|
||
services.AddSingleton<TempFiles>();
|
||
services.AddScoped<PDFBurner>();
|
||
services.AddScoped<PDFMerger>();
|
||
services.AddScoped<ReportCreator>();
|
||
|
||
//TODO: Check lifetime of services. They might be singleton or scoped.
|
||
services.AddTransient<GdViewer>();
|
||
// Add LicenseManager – license key is read from DB via MediatR
|
||
services.AddTransient(provider =>
|
||
{
|
||
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(licenseKey);
|
||
return licenseManager;
|
||
});
|
||
services.AddTransient<AnnotationManager>();
|
||
|
||
return services;
|
||
}
|
||
} |