Skip to content

Configuration refresh does not work when ChainedConfigurationProvider is used #168

Closed

Description

@zhenlan

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 (@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 (@drago-draganov) AA (@abhilasharora) Jimmy Campbell (@jimmyca15)

Activity

  1. removed this from the v4.1.0 milestone on Dec 10, 2020
  2. zhenlan commented on Oct 15, 2021

    @zhenlan
    MemberAuthor

    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.

  3. cwe1ss commented on Oct 13, 2022

    @cwe1ss

    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?

  4. zhenlan commented on Oct 13, 2022

    @zhenlan
    MemberAuthor

    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

  5. cwe1ss commented on Oct 13, 2022

    @cwe1ss

    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?

  6. zhenlan commented on Oct 13, 2022

    @zhenlan
    MemberAuthor

    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

  7. cwe1ss commented on Oct 14, 2022

    @cwe1ss

    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.

  8. kevinferretti commented on Oct 24, 2022

    @kevinferretti

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

  9. zhenlan commented on Oct 24, 2022

    @zhenlan
    MemberAuthor

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

    Avani Gupta (@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

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions