Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.Net Core App Configuration Dynamic Configuration doesn't refresh array values #357

Closed
willyt150 opened this issue Jun 26, 2020 · 7 comments
Assignees
Labels
.NET Config Provider Issues related to the AppConfig .NET Core configuration provider. question

Comments

@willyt150
Copy link

willyt150 commented Jun 26, 2020

Hello,

This is for an Asp.net core 3.1 project using Microsoft.Extensions.Configuration.AzureAppConfiguration 3.0.1.

I mimicked the Tutorial: Use dynamic configuration in an ASP.NET Core app and when I change the "Sentinel" value along with non-array values in the Azure App Configuration portal, I almost immediately see the change.

However, when I change an array value, or attempt to add another entry in the array, in the portal and then change the "Sentinel" value, nothing happens. I have to completely restart my site to see the update.

I'm defining the arrays like this in the portal:
Key:Subkey:0
Key:Subkey:1
Key:Subkey:2

This closed issue for Support single-value arrays shows being able to specify an array in the portal as Key:Subkey (without the indexing) and specify an actual array as the value ["val1", "val2", etc...].

I tried this approach thinking maybe that would solve my issue and I was able to confirm that it did refresh, however going this approach doesn't bind the array to the appropriate property when I use IOptions.

Or do I need to treat that array config value as a string and have my Options class convert it into an array like in this comment in issue #242

Thanks!

@shenmuxiaosen
Copy link

Hi willyt150 , defining arrays using index is fine in Asp.net core. So for items like

Key:Subkey:0
Key:Subkey:1
Key:Subkey:2

services.Configure<Key>(Configuration.GetSection("Key"));

It will bind to the object

public class Key
{
    public List<string> Subkey{ get; set; }
}

@willyt150
Copy link
Author

Thanks @shenmuxiaosen, sorry yes I know that approach works great.

My issue is that if I go that approach and I change the value of one of those items or add another item (Key:Subkey:3), in the Azure App Configuration, it doesn't refresh the values of the Key class. I have to restart the App Service hosting the site for it to get those new values.

However, if the setting is NOT an array (e.g. Key:Subkey) changing that value in the Azure App Configuration, and changing the sentinel value, will refresh without any problem.

@abhilasharora
Copy link
Contributor

@willyt150 Could you share the code snippet that you used to configure App Configuration?

@willyt150
Copy link
Author

@abhilasharora sure thing

In the Program.cs inside the IWebHostBuilder.ConfigureAppConfiguration I configure the App Configuration with the following:

config.AddAzureAppConfiguration(options =>
	{
		options.Connect(azureAppConfigurationConnectionString)
			.UseFeatureFlags()
			.ConfigureRefresh(configure =>
			{
				configure.Register(GlobalConstants.SentinelKey, refreshAll: true);
			});
	});

And I call the app.UseAzureAppConfiguration(); within the Configure method of the Startup class.

@abhilasharora
Copy link
Contributor

abhilasharora commented Jun 30, 2020

An object T associated with an IOptions<T> instance does not change when the underlying configuration is updated. The values are fixed the first time you access the IOptions<T>.Value property. In case you'd like configuration updates to be reflected in your T instance, IOptionsSnapshot<T> or IOptionsMonitor<T> can be used instead. You can find details on the differences here.

@abhilasharora abhilasharora self-assigned this Jun 30, 2020
@abhilasharora abhilasharora added .NET Config Provider Issues related to the AppConfig .NET Core configuration provider. question labels Jun 30, 2020
@willyt150
Copy link
Author

Oh... That makes sense. I guess when I was confirming that the changes had refreshed I was looking at the IConfiguration.

Ok, I'll give those a try tomorrow. Thank you!

@willyt150
Copy link
Author

Thank you @abhilasharora

The IOptionsMonitor was what I was looking for and worked like a charm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
.NET Config Provider Issues related to the AppConfig .NET Core configuration provider. question
Projects
None yet
Development

No branches or pull requests

3 participants