public class ConfigTest:IOptions<ConfigTest>
{
public int TotalCount { get; set; }
public List<Student> Students { get; set; }
public ConfigTest Value => this;
}
读取json
public class ConfigController : Controller
{
private ConfigTest _configTestByOptions;
private readonly IConfiguration _configuration;
public ConfigController(IConfiguration configuration)
{
_configuration = configuration;
}
public IActionResult Index()
{
//GetSection:必须先读节点
//ConfigTest实现接口IOptions<ConfigTest>
_configTestByOptions = _configuration.GetSection("MyData").Get<ConfigTest>();
return View();
}
}