我有一个在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.
}
这些选项似乎与应用程序启动时存在的选项相同。知道为什么他们没有重装吗?
答案 0 :(得分:2)
如果您需要IOptionsSnapshot<>
来响应配置中的更改
val l1 = Seq(1,2,3,4,5,6,7,8,9,0)
val l2 = Seq(2,4,6,8,10,12)