在ASP.Net Core中,可以使用IOptions<T>
将配置值注入类中。ASP.Net核心注入设置
所以,如果我有以下appsettings.json
配置:
{
"CustomSection": {
"Foo": "Bar"
},
"RootUrl": "http://localhost:12345/"
}
我可以注入IOptions<CustomSection>
到我的构造函数(假设我已经定义了一个CustomSection
类)和阅读Foo
属性。
如何将RootUrl
设置注入到我的构造函数中或者不支持?
你不能构建一类'RootUrl' – Daniel
你应该[不要注入IOptions到你的构造函数中](https://github.com/simpleinjector/SimpleInjector/issues/143#issuecomment-155029876)。 –
Steven