[英]How to bind nested json configuration to options in .net core
In .net core if we have to bind the configuration directly from Json configuration as shown below在 .net 内核中,如果我们必须直接从 Json 配置中绑定配置,如下所示
{
"AzureAdJwtSettings": {
"Authority": "https://login.microsoftonline.com/tenantid",
},
"WebSecJwtSettings": {
"Authority": "https://example.com",
}
}
we can write something like this我们可以写这样的东西
configuration.Bind("AzureAdJwtSettings", options);
I am looking to find a way so that I can group my json configuration in such a way我正在寻找一种方法,以便我可以以这种方式对我的 json 配置进行分组
{
"JwtSettings": {
"AzureAdJwtSettings": {
"Authority": "https://login.microsoftonline.com/tenantid"
},
"WebSecJwtSettings": {
"Authority": "https://example.com"
}
}
}
But when I try to load the configuration in my code it didn't load properly.. I am using the below code但是当我尝试在我的代码中加载配置时,它没有正确加载。我正在使用下面的代码
configuration.Bind("JwtSettings.AzureAdJwtSettings", options);
I know there must be way to load nested properties but couldn't find it working...我知道必须有办法加载嵌套属性,但找不到它工作......
As per suggested comments, the format should use colon ( :
) instead of dot ( .
) with keys for configuration option binding to work根据建议的评论,格式应使用冒号 ( :
) 而不是点 ( .
) 与配置选项绑定工作的键
For example例如
configuration.Bind("JwtSettings:AzureAdJwtSettings", options);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.