不知道我在这里缺少什么,但是我无法从.net核心应用程序中的appsettings.json获取值。我有我的appsettings.json为:{ "AppSettings": { "Version": "One" }}启动:public class Startup{ private IConfigurationRoot _configuration; public Startup(IHostingEnvironment env) { _configuration = new ConfigurationBuilder() } public void ConfigureServices(IServiceCollection services) { //Here I setup to read appsettings services.Configure<AppSettings>(_configuration.GetSection("AppSettings")); }}模型:public class AppSettings{ public string Version{ get; set; }}控制器:public class HomeController : Controller{ private readonly AppSettings _mySettings; public HomeController(IOptions<AppSettings> settings) { //This is always null _mySettings = settings.Value; }}_mySettings始终为null。我在这里缺少什么吗?
3 回答
- 3 回答
- 0 关注
- 1071 浏览
添加回答
举报
0/150
提交
取消