我写了一个自定义ConfigurationProvider
与实体框架。因为我还想让它在运行时可更新,所以我创建了一个IWritableableOption https://stackoverflow.com/a/42705862/2441442.
更新后我需要刷新配置。这可以通过以下方式完成IConfigurationRoot.Reload https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.configuration.iconfigurationroot.reload?view=aspnetcore-2.0.
然而,我怎样才能得到IConfigurationRoot
在.net核心2中?
我发现,在以前的版本中IConfigurationRoot
是启动的一部分。然而,在 .net core 2 中,我们只有更简单的类型IConfiguration
:
public Startup(IConfiguration configuration)
{
// I tried to change this to IConfigurationRoot,
// but this results in an unresolved dependency error
Configuration = configuration;
}
public IConfiguration Configuration { get; }
我还发现,我可以使用我自己的实例
WebHost.CreateDefaultBuilder(args).ConfigureAppConfiguration(context, builder) => {
var configurationRoot = builder.build()
})
但我想更新启动使用的配置。
那么我怎样才能得到IConfigurationRoot
被使用过Startup
将其注入我的服务集合中?
谢谢迪尔黛安的 https://stackoverflow.com/questions/48939567/how-to-access-iconfigurationroot-in-startup-on-net-core-2#comment84887990_48939567评论。
我们可以沮丧IConfiguration
:
public Startup(IConfiguration configuration)
{
Configuration = (IConfigurationRoot)configuration;
}
public IConfigurationRoot Configuration { get; }
我仍然不确定这是否是预期的方式,因为IConfiguration
不做任何保证IConfigurationRoot
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)