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

Configuration refresh does not work when ChainedConfigurationProvider is used #168

Closed
zhenlan opened this issue Jun 5, 2020 · 8 comments · Fixed by #371
Closed

Configuration refresh does not work when ChainedConfigurationProvider is used #168

zhenlan opened this issue Jun 5, 2020 · 8 comments · Fixed by #371
Assignees
Labels
enhancement New feature or request

Comments

@zhenlan
Copy link
Contributor

zhenlan commented Jun 5, 2020

Problem

A user added the App Configuration middleware to their application, but the configuration is not refreshed.

Cause

The AzureAppConfigurationProvider could be nested under a ChainedConfigurationProvider if the user calls IConfigurationBulder.AddConfiguration(...) to add configuration built from the App Configuration provider.

Unfortunately, ChainedConfigurationProvider does not provide a way for others to access its child providers. This caused the issue that the App Configuration middleware could not find the instance of AzureAppConfigurationProvider and thus cannot obtain the instance of IConfigurationRefresher.

Proposal

There is no good solution to this. One idea from @drago-draganov is we provide an alternative API for users to call (the name is to be finalized)

public static IConfigurationBuilder AddConfiguration2(this IConfigurationBuilder configurationBuilder, IConfiguration config);

Under the cover, this API will add a type derived from ChainedConfigurationProvider and this type we write exposes child providers.

As part of fixing #166, we can provide additional information and suggest users to call this new API in the exception message.

Reference

The code of ChainedConfigurationProvider can be found at
https://github.com/dotnet/runtime/tree/master/src/libraries/Microsoft.Extensions.Configuration/src

cc: @drago-draganov @abhilasharora @jimmyca15

@zhenlan
Copy link
Contributor Author

zhenlan commented Oct 15, 2021

This is not a viable solution in .NET 6 as the user is not the one calling IConfigurationBulder.AddConfiguration. The framework uses ChainedConfigurationProvider by default.

@cwe1ss
Copy link

cwe1ss commented Oct 13, 2022

I also can't get the refresh to work with .NET 7 RC2 and the new minimal API-style Program.cs. I also have a ChainedConfigurationProvider in my list of providers:

image

Is there any workaround for this?

@zhenlan
Copy link
Contributor Author

zhenlan commented Oct 13, 2022

Please add App Configuration provider directly to your configuration builder instead of nested under the ChainedConfigurationProvider. Here is a code sample for .NET 6.

https://learn.microsoft.com/en-us/azure/azure-app-configuration/enable-dynamic-configuration-aspnet-core?tabs=core6x#reload-data-from-app-configuration

@cwe1ss
Copy link

cwe1ss commented Oct 13, 2022

Thank you for the quick response! I have been using that link for my implementation.

I did some more quick testing and the ChainedConfigurationProvider is already there from the beginning:
image

And here's how it looks after AddAzureAppConfiguration():
image

The AzureAppConfigurationProvider has been added to the list and isn't a child of ChainedConfigurationProvider.

Anything else I can do?

@zhenlan
Copy link
Contributor Author

zhenlan commented Oct 13, 2022

Is this a web app? If so, you should also add App Configuration middleware as instructed in the same document. It will take care of the configuration refresh.

If it's a console app, you will need to call TryRefreshAsync in your code to get the configuration refreshed. You can find more details in this doc for a console app.
https://learn.microsoft.com/en-us/azure/azure-app-configuration/enable-dynamic-configuration-dotnet-core

@cwe1ss
Copy link

cwe1ss commented Oct 14, 2022

I'm so sorry, I seem to have just stopped reading after the step to add builder.Services.AddAzureAppConfiguration() and I haven't added the middleware. One shouldn't program late at night 😪

thank you very much for your help, it is working now.

@kevinferretti
Copy link

Now that the ChainedConfigurationProvider exposes its IConfiguration as per dotnet/runtime#44486, is this issue able to be fixed?

@zhenlan
Copy link
Contributor Author

zhenlan commented Oct 24, 2022

Yes, but that's only available in .NET 7.

@avanigupta, we need to code this so it will "light up" when running in a .NET 7 app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
4 participants