1

I am using azure app configuration with azure function. So i want to refresh the keys automatically but i am getting configurationRefresher as null always.

 builder.AddAzureAppConfiguration(appConfigurationOptions =>
            {
                appConfigurationOptions
                    .Select(ConfigurationKeys.AZURE_FUNC_TEST)
                    .Select(KeyFilter.Any, environment.EnvironmentName)
                    .ConfigureRefresh(refreshOptions =>
                    {
                        refreshOptions.Register(ConfigurationKeys.AZURE_FUNC_TEST, true);
                        refreshOptions.SetCacheExpiration(TimeSpan.FromMinutes(1));
                    })
                    .UseFeatureFlags(flagOptions =>
                    {
                        flagOptions.Label = environment.EnvironmentName;
                        flagOptions.CacheExpirationInterval = TimeSpan.FromSeconds(30);
                    })
                    .GetRefresher();
                configurationRefresher = appConfigurationOptions.GetRefresher();
            },true);
            return builder;

I found the reason why it is null actually i have the above code in a helper class and then i am passing the above result to the startup class and then in startup class it builds. Hence i am not getting value. But is there any way to get the value in startup class and above code i want it in helper class

Ekta
  • 261
  • 1
  • 2
  • 11

1 Answers1

0

The AddAzureAppConfiguration method takes a delegate as input. This delegate runs only when Build method is invoked on the ConfigurationBuilder instance.

In order to get the configurationRefresher instance initialized in your helper class, you could invoke the ConfigurationBuilder.Build method to get an instance of IConfiguration. This instance could then be registered in the dependency injection container.

IConfiguration configuration = builder.AddAzureAppConfiguration(appConfigurationOptions =>
{
    appConfigurationOptions
        .Select(ConfigurationKeys.AZURE_FUNC_TEST)
        .Select(KeyFilter.Any, environment.EnvironmentName)
        .ConfigureRefresh(refreshOptions =>
        {
            refreshOptions.Register(ConfigurationKeys.AZURE_FUNC_TEST, true);
            refreshOptions.SetCacheExpiration(TimeSpan.FromMinutes(1));
        })
        .UseFeatureFlags(flagOptions =>
        {
            flagOptions.Label = environment.EnvironmentName;
            flagOptions.CacheExpirationInterval = TimeSpan.FromSeconds(30);
        })
        .GetRefresher();

    configurationRefresher = appConfigurationOptions.GetRefresher();
}, true);

return configuration;
Abhilash Arora
  • 277
  • 2
  • 4