【发布时间】:2018-11-27 06:43:29
【问题描述】:
我在 appsettings.json 中有一个配置,例如:
"ClientId": {
"US": {
"xxxxxxxx": [ "xxxxxxxx" ]
},
"UK": {
"xxxxxxxx": [ "xxxxxxxx" ]
},
"PK": {
"xxxxxxxx": [ "xxxxxxxx" ]
},
"DK": {
"xxxxxxxx": [ "xxxxxxxx" ]
},
"IN": {
"xxxxxxxx": [ "xxxxxxxx" ]
},
"LV": {
"xxxxxxxx": [ "xxxxxxxx" ]
},
"EE": {
"xxxxxxxx": [ "xxxxxxxx" ]
}
}
现在我想将此部分映射到一个字典中,例如:
public class ClientIds
{
public Dictionary<string, List<string>> US { get; set; }
public Dictionary<string, List<string>> UK { get; set; }
public Dictionary<string, List<string>> PK { get; set; }
public Dictionary<string, List<string>> DK { get; set; }
public Dictionary<string, List<string>> IN { get; set; }
public Dictionary<string, List<string>> LV { get; set; }
public Dictionary<string, List<string>> EE { get; set; }
}
但我每次都得到空值。这是我的启动配置:
services.Configure<ClientIds>((settings) =>
{
Configuration.GetSection("ClientId").Bind(settings);
});
这是我的服务注入:
private readonly ClientIds _clientIds;
public MyService(IOptions<ClientIds> clientIds)
{
_clientIds = clientIds.Value;
}
这里有什么问题?
【问题讨论】:
-
您的示例代码对我有用。你能创建一个minimal reproducible example吗?
标签: .net json asp.net-core