configuration - 如何在 dotnet-isolated (net5.0) azure 函数中使用 IOptions 模式进行配置
问题描述
我正在尝试将现有的 Functions 应用程序从 core3.1 v3 移植到 net5.0,但不知道如何使 IOptions 配置模式正常工作。
我的配置local.settings.json
存在于配置数据中,我可以使用 GetEnvironmentVariable 来获取它。尽管如此,以下内容并没有像以前那样将值绑定到 IOptions 配置。
.Services.AddOptions<GraphApiOptions>()
.Configure<IConfiguration>((settings, configuration) => configuration.GetSection("GraphApi").Bind(settings))
这些值与local.settings.json
以前一样:
"GraphApi:AuthenticationEndPoint": "https://login.microsoftonline.com/",
"GraphApi:ClientId": "316f9726-0ec9-4ca5-8d04-f39966bebfe1",
"GraphApi:ClientSecret": "VJ7qbWF-ek_Amb_e747nXW-fMOX-~6b8Y6",
"GraphApi:EndPoint": "https://graph.microsoft.com/",
"GraphApi:TenantId": "NuLicense.onmicrosoft.com",
这仍然支持吗?我错过了什么?
解决方案
我有同样的问题,但结果是json 格式不正确。
仅供参考,这是我的配置方式:
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureServices(s =>
{
s.AddOptions<ApplicationSettings>().Configure<IConfiguration>((settings, configuration) =>
{
configuration.GetSection(nameof(ApplicationSettings)).Bind(settings);
});
})
.Build();
以下是 local.setting.json 的示例:
{
"IsEncrypted": false,
"Values": {
"ApplicationSettings:test": "testtest",
"ApplicationSettings:testtest": "test"
}
}
推荐阅读
- c# - 如何使用 c# 在 SSMS(SQL Server Management Studio) 17 的标题栏中设置自定义文本
- singleton - EJB Singleton 是否同步?
- neo4j - Neo4j - 检查顺序路径是否存在
- spring-boot - 在 Spring Boot 上调用 GenericFilterBean 的 doFilter() 后返回
- google-sheets - 谷歌表格根据单词列表识别单元格中的银行动作
- c# - 添加 .NET Standard 2.0 类库项目后,UWP 应用项目出错
- python - 获取包含特定值的多列的行的列名(Python 3)
- node.js - 如何查找节点服务器提供哪些文件?
- kubernetes - 如何检查 Kubernetes 集群是否运行良好
- selenium - 对 URL 的远程 WebDriver 服务器的 HTTP 请求...在 60 秒后超时