I am using azure app configuration and azure function.
So i am pulling all the key value from azure app configuration. But if the azure function is running and if i make any changes in key value from azure app configuration, azure func will not show the updated value.
Below is the code that i have implemented
in startup.cs
public override void Configure(IFunctionsHostBuilder builder)
{
var environmentName = Environment.GetEnvironmentVariable("AZURE_FUNCTIONS_ENVIRONMENT");
if (string.IsNullOrWhiteSpace(environmentName))
throw new Exception("AZURE_FUNCTIONS_ENVIRONMENT could not be resolved.");
var hostEnvironment = new HostEnvironment { EnvironmentName = environmentName };
var config = SetUpConfiguration(builder.Services, hostEnvironment);
var appSettings = config.Get<TSettings>();
appSettings.AppName = _appName;
builder.Services.AddSingleton<ICorrelationIdProvider>(new FunctionAppCorrelationIdProvider());
builder.Services.AddSingleton<IIdentityProvider>(new FunctionAppIdentityProvider(appSettings.AppName));
builder.Services.AddSingleton<IHostEnvironment>(hostEnvironment);
builder.Services.AddSingleton(appSettings);
}
private IConfiguration SetUpConfiguration(IServiceCollection services, IHostEnvironment environment)
{
var executionContextOptions = services.BuildServiceProvider().GetService<IOptions<ExecutionContextOptions>>().Value;
var configBuilder = new ConfigurationBuilder().Initialize(environment, executionContextOptions.AppDirectory);
var config = configBuilder.Build();
services.AddSingleton<IConfiguration>(new ConfigurationRoot(config.Providers.ToArray()));
return config;
}
in a helper class i have written the below code
builder.AddAzureAppConfiguration(appConfigurationOptions =>
appConfigurationOptions
.Connect(new Uri(config["AppConfig:Endpoint"]), tokenCredential)
.Select(ConfigurationKeys.AZURE_FUNC_TEST)
.Select(KeyFilter.Any, environment.EnvironmentName)
.ConfigureRefresh(refreshOptions =>
{
refreshOptions.Register(ConfigurationKeys.AZURE_FUNC_TEST, false);
refreshOptions.SetCacheExpiration(TimeSpan.FromMinutes(1));
})
);
return builder;
in azure function i am using the below code to get the value
var test = _settings.AzureFuncTest;
but here i dont get the new value until i dont restart the azure functions.