refactor: simplify GdPicture license resolution in dependency injection

This commit is contained in:
tekh 2025-11-10 13:29:02 +01:00
parent f8369e350f
commit d2e8f1fc5e

View File

@ -52,14 +52,11 @@ public static class DependencyInjection
services.Configure<TotpSmsParams>(config.GetSection(nameof(TotpSmsParams)));
services.Configure<PDFBurnerParams>(config.GetSection(nameof(PDFBurnerParams)));
services.AddOptions<GdPictureParams>()
.Configure((GdPictureParams opt, IServiceProvider sp) =>
.Configure((GdPictureParams opt, IServiceProvider provider) =>
{
var licenseKey = "GDPICTURE";
using var scope = sp.CreateScope();
var mediator = scope.ServiceProvider.GetRequiredService<IMediator>();
opt.License = config["GdPictureLicenseKey"]
?? mediator.ReadThirdPartyModuleLicenseAsync(licenseKey).GetAwaiter().GetResult()
?? throw new InvalidOperationException($"License record not found for key: {licenseKey}");
?? provider.GetRequiredService<IMediator>().ReadThirdPartyModuleLicenseAsync("GDPICTURE").GetAwaiter().GetResult()
?? throw new InvalidOperationException($"License record not found for key: {"GDPICTURE"}");
});
services.AddSingleton(provider => {
var license = provider.GetRequiredService<IOptions<GdPictureParams>>().Value.License;