【发布时间】:2020-04-30 12:01:22
【问题描述】:
让我们考虑以下用于配置 Azure 功能的类:
internal class Configuration
{
private readonly IConfigurationRoot config;
public Configuration(ExecutionContext context)
{
config = new ConfigurationBuilder()
.SetBasePath(context.FunctionAppDirectory)
.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
}
public bool MyFlag
{
get => bool.TryParse(config[nameof(MyFlag)], out var value) ? value : false;
set => config[nameof(MyFlag)] = value.ToString();
}
}
该函数可以轻松地从应用设置中读取 MyFlag 属性。
但我希望我的函数也能够在 azure 函数应用设置中设置 MyFlag 属性的值。不幸的是,该值在 Azure 和本地环境中都没有改变。
我试着像这样绑定属性
config.Bind("Values", this);
在Configuration 类构造函数中,它只在本地环境中有效。但是,它不适用于 Azure 环境。
是否可以将值从 azure 函数存储到应用设置?
【问题讨论】:
标签: c# azure azure-functions appsettings