refactor: simplify GdPicture license resolution in dependency injection
This commit is contained in:
parent
f8369e350f
commit
d2e8f1fc5e
@ -52,14 +52,11 @@ public static class DependencyInjection
|
|||||||
services.Configure<TotpSmsParams>(config.GetSection(nameof(TotpSmsParams)));
|
services.Configure<TotpSmsParams>(config.GetSection(nameof(TotpSmsParams)));
|
||||||
services.Configure<PDFBurnerParams>(config.GetSection(nameof(PDFBurnerParams)));
|
services.Configure<PDFBurnerParams>(config.GetSection(nameof(PDFBurnerParams)));
|
||||||
services.AddOptions<GdPictureParams>()
|
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"]
|
opt.License = config["GdPictureLicenseKey"]
|
||||||
?? mediator.ReadThirdPartyModuleLicenseAsync(licenseKey).GetAwaiter().GetResult()
|
?? provider.GetRequiredService<IMediator>().ReadThirdPartyModuleLicenseAsync("GDPICTURE").GetAwaiter().GetResult()
|
||||||
?? throw new InvalidOperationException($"License record not found for key: {licenseKey}");
|
?? throw new InvalidOperationException($"License record not found for key: {"GDPICTURE"}");
|
||||||
});
|
});
|
||||||
services.AddSingleton(provider => {
|
services.AddSingleton(provider => {
|
||||||
var license = provider.GetRequiredService<IOptions<GdPictureParams>>().Value.License;
|
var license = provider.GetRequiredService<IOptions<GdPictureParams>>().Value.License;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user