更新时间:2023-02-14 14:19:09
此处是Microsoft的有关.Net Core Apps中的配置设置的相关文章:
Here is a relevant article from Microsoft regarding Configuration setup in .Net Core Apps:
该页面还具有示例代码可能也有帮助.
The page also has sample code which may also be helpful.
更新
我认为内存提供程序并绑定到POCO类可能有用,但不能按OP预期的那样工作.
I thought In-memory provider and binding to a POCO class might be of some use but does not work as OP expected.
The next option can be setting reloadOnChange
parameter of AddJsonFile to true while adding the configuration file and
manually parsing the JSON configuration file and making changes as intended.
public class Startup
{
...
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
}
...
}
...
reloadOnChange
仅在ASP.NET Core 1.1和更高版本中受支持.
...
reloadOnChange
is only supported in ASP.NET Core 1.1 and higher.