Define custom "per application" setting which is read after app start from DB using appservice. How? SettingDefinitionProvider does not fit here?
ABP 4.3.0 / Angular.
I need to define custom setting for application. In my case it's an application version which is stored in DB and changed manually after next deployment (accessible via appservice method) and needs to be read once ONCE application start and be accessible from Angular client.
I can see SettingDefinitionProvider inherited class is adviced, where in Define method new settings are added. But it's a transient class and besides, Define method is sync. How to implement my requirement properly? It needs to be something like:
public class Program
{
public static async Task Main(string[] args)
{
IWebHost webHost = CreateWebHostBuilder(args).Build();
// Create a new scope
using (var scope = webHost.Services.CreateScope())
{
// Get the MyVersionAppService instance
var myVersionAppService = scope.ServiceProvider.GetRequiredService<MyVersionAppService>();
//Get app version asynchronously
var actualVersion = await myVersionAppService.GetAppVersionAsync('MY_APP_NAME');
//TODO: add 'actualVersion' into 'SettingDefinition' somehow...
}
// Run the WebHost, and start accepting requests
// There's an async overload, so we may as well use it
await webHost.RunAsync();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
}
Seems like I can use it like that:
try
{
Log.Information("Starting AbxEps.Fines.HttpApi.Host.");
var host = CreateHostBuilder(args).Build();
using var scope = host.Services.CreateScope();
var configuration = scope.ServiceProvider.GetRequiredService<IConfiguration>();
var versionRepository = scope.ServiceProvider.GetRequiredService<IVersionRepository>();
var version = await versionRepository.GetAsync('MY_APP_NAME');
configuration["app_version"] = version;
await host.RunAsync();
}
catch (Exception ex)
{
Log.Fatal(ex, "Host terminated unexpectedly!");
}
finally
{
Log.CloseAndFlush();
}
Hi,
Can you please check the documentation https://docs.abp.io/en/abp/latest/Settings
You don't need to make anything in the Program.cs
@cotur Hi - I've already read this part. And that's why I expressed my doubt in the title: "SettingDefinitionProvider does not fit here?" I doubt because:
- it is not clear when
SettingDefinitionProvidercomes into game. I need to make sure everything happens ONCE on application start; Definemethod is SYNC, as I mentioned. And I need to call the appservice or repository method which is ASYNC. I don't want to wait till DB request finishes.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.