我对我的一些类使用 IOptions 模式作为配置。我需要在这个选项类中使用
Dictionary<Uri, Uri>
:
public class CdnOptions
{
public const string CONFIG_SECTION_NAME_S = "CdnTransformationOptions";
public bool EnableCdnTransformations { get; set; }
public Dictionary<string, string> CdnTransformRules { get; set; } = [];
}
这就是我绑定这些选项的方式:
services.AddOptions<CdnOptions>().Bind(configuration.GetSection(CdnOptions.CONFIG_SECTION_NAME_S))
.ValidateDataAnnotations();
appsettings.json包含数据如下:
CdnTransformationOptions": {
"EnableCdnTransformations": true,
"CdnTransformRules": {
"https://localhost:7021": "https://cdn.mydomain.com"
}
},
但是无论我如何更改 json,我都会得到一个空字典。我也尝试使用简单的
Dictionary<string, string>
而不是 Dictionary<Uri, Uri>
,但得到相同的结果。
这里缺少什么?
问题是地址包含“:”字符,键中不允许使用