我有一个.Net Core 3.1应用程序,在启动时,我需要从KV中读取一些秘密。由于此操作是异步的,因此这是我使用的方法。
public void ConfigureServices(IServiceCollection services)
{
...
services.AddSingleton(Configuration);
services.AddApplicationSettings(Configuration);
...
}
public static IServiceCollection AddApplicationSettings(this IServiceCollection services, IConfiguration configuration)
{
var applicationSettings = new ApplicationSettings(configuration);
applicationSettings.ReadApplicationSettingsAsync().Wait();
services.AddSingleton<IApplicationSettings>(applicationSettings);
return services;
}
是否可以通过异步方式获取,所以我无需调用.Wait();