从旧的ASP.NET MVC 4.5迁移到ASP.NET Core。以前在web.config中有一些自定义设置-现在该怎么办?
出现在guide上,基本上告诉您编辑Startup.cs并在此处添加几行:
在点击率中:
.AddJsonFile($"customSettings.json", optional: true, reloadOnChange: true)
在ConfigureServices(...)中:
services.Configure<CustomSection1>(options => Configuration.GetSection("CustomSection1").Bind(options));
services.Configure<CustomSection2>(options => Configuration.GetSection("CustomSection2").Bind(options));
现在,我是一个KISS类型的人,所以有什么原因使我无法简单地进行:
public static T Settings = Newtonsoft.Json.JsonConvert.DeserializeObject<T>(System.IO.File.ReadAllText("custom.json"));
以前的例子很适合注射。除此之外呢?