【发布时间】:2019-03-13 03:01:32
【问题描述】:
现在我们可以使用来自 .NETCore 的极其灵活的配置引擎 - 我们可以这样做:
private static IConfigurationRoot SetConfig(ExecutionContext executionContext)
{
return new ConfigurationBuilder()
.SetBasePath(executionContext.FunctionAppDirectory)
.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
}
这很棒,因为它允许您将更复杂的配置数据放入配置文件中 - 例如
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "<< removed >>",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"APPINSIGHTS_INSTRUMENTATIONKEY": "<< removed >>"
},
"MyCustomSettings": [
{
"ConnectionString": "<< removed >>",
"Folders": [
{
"ShareName": "share1",
"FolderName": "folder1"
},
{
"ShareName": "share2",
"FolderName": "folder2"
}
]
}
]
}
再次 - 好消息!我现在可以使用 config["MyCustomSettings"]
访问我的强类型配置但我不明白 - 在发布函数时如何部署它。只有值部分迁移到 Azure 函数应用程序设置。我显然可以将此自定义 json 放在 json 文件中,并将其添加到 load 语句中,如 local.settings.json
.AddJsonFile("my-custom-settings.json", optional: false, reloadOnChange: true)
但是这个文件必须包含在部署中,并且没有安全存储。
有什么想法吗?
【问题讨论】:
标签: azure configuration azure-functions