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(configuration.GetSection("Worker")); services.AddSingleton(provider => { var options = provider.GetRequiredService>().Value; var manager = new JobStateManager(options.InitialJobState); return manager; }); services.AddScoped(); services.AddScoped(); services.AddSingleton(); services.AddScoped(); services.AddScoped(); services.AddScoped(); //TODO: Check lifetime of services. They might be singleton or scoped. services.AddTransient(); // Add LicenseManager – license key is read from DB via MediatR services.AddTransient(provider => { using var scope = provider.CreateScope(); var mediator = scope.ServiceProvider.GetRequiredService(); var licenseKey = mediator.Send(new ReadThirdPartyModuleLicenseQuery { Name = "GdPicture" }).GetAwaiter().GetResult(); var licenseManager = new LicenseManager(); licenseManager.RegisterKEY(licenseKey); return licenseManager; }); services.AddTransient(); return services; } }