Let's consider the following class that I'm using for a configuration for my Azure function:
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();
}
}
The function can easily read the MyFlag property out of the app settings.
But I want my function to be able to set the value of the MyFlag property in azure function app settings as well. Unfortunately, the value doesn't get changed on both Azure and local environments.
I tried to bind the property like this
config.Bind("Values", this);
in the Configuration
class constructor and it works but only on local environment. However, it doesn't work on Azure environment.
Is it possible to store the value to the app settings from azure function?