reloadOnChange 在 .NET Core 2 中不起作用

reloadOnChange Not Working in .NET Core 2

我在 netcore2 下有一个 ASP.NET Core 2 项目 运行。我正在覆盖 BuildWebHost 以添加新的 JSON 配置文件,如下所示:

public static IWebHost BuildWebHost(string[] args) =>
    WebHost.CreateDefaultBuilder(args)
        .ConfigureAppConfiguration((hostingContext, config) =>
        {
            config.AddJsonFile("mysettings.json", optional: false, reloadOnChange: true);
        })
        .UseStartup<Startup>()
        .Build();

但是,在控制器的 ActionFilter 中,我试图像这样抓住它:

public override void OnActionExecuting(ActionExecutingContext filterContext)
{
    base.OnActionExecuting(filterContext);

    var options = filterContext.HttpContext.RequestServices.GetService(typeof(IOptions<MySettings>));

    /// Do something with the options.
}

这些选项似乎仍然与应用程序启动时存在的选项相同。知道他们为什么不重新加载吗?

如果需要它响应配置中的更改,请使用 IOptionsSnapshot<>