我们有一些常用的4.5.2类库 ConfigurationManager.AppSettings[key]
是否可以在.net core 2应用程序中引用这些内容,以便在引擎盖下正确修补配置?即旧的调用ConfigurationManager.AppSettings[key]
正确读取配置,从json或xml,但在.netcore2应用程序内.
如果我将keys
问题移植到appSettings.json,则调用ConfigurationManager.AppSettings
始终返回null.
一个例子是:
{
"Logging": {
"IncludeScopes": false,
"Debug": {
"LogLevel": {
"Default": "Warning"
}
},
"Console": {
"LogLevel": {
"Default": "Warning"
}
}
},
"appSettings": {"test": "bo"},
"test": "hi"
}
Run Code Online (Sandbox Code Playgroud)
然后:
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2", ConfigurationManager.AppSettings["test"] , ConfigurationManager.AppSettings["appSettings:test"] };
}
Run Code Online (Sandbox Code Playgroud)
将显示:
["value1","value2",null,null]
Run Code Online (Sandbox Code Playgroud) 如果您向要添加到 Redis 的实体添加过期时间,例如在 ServiceStack.Redis 中:
redisClient.Set(elementKey, "some cached value", DateTime.Now.AddMinutes(2));
Run Code Online (Sandbox Code Playgroud)
那么您如何订阅该元素的到期时间。期望的结果是:
redisClient.Subscribe(elementKey, "expire", DoSomethingBasedOnKey)
Run Code Online (Sandbox Code Playgroud)