Git Product home page Git Product logo

Comments (2)

zhenlan avatar zhenlan commented on June 19, 2024 2

Thanks for trying this out @kamalsivalingam.

By default, the config provider of the App Configuration will load keys with no labels for simplicity. When labels are used, they can be loaded with the Use function. The example below loads all keys with the label mylabel.

configBuilder.AddAzureAppConfiguration(options =>
{
    options.Connect(configuration["connection_string"])
           .Use(KeyFilter.Any, "mylabel")
});

Labels provide an extra dimension to key-values, so each key can have multiple values at the same time. It can be used to differentiate config for different environments (dev, test, ...), different microservices (app1, app2, ...), different regions and so on so forth. We also expect it will be a very typical use of labels for versioning. For example, I have config labeled with v1 and v2. In my app, I want the v2 config overwrites the v1 config when they have the same key. Then I will have something like this

configBuilder.AddAzureAppConfiguration(options =>
{
    options.Connect(configuration["connection_string"])
           .Use(KeyFilter.Any, "v1")
           .Use(KeyFilter.Any, "v2")
});

Please check out the AzureAppConfigurationOptions class, which provides APIs for filtering key-values, watching for changes, connecting with managed identity and so on.

Hope this helps. Please let me know if you have any other questions.

from appconfiguration.

sabbadino avatar sabbadino commented on June 19, 2024

I've added 2 keys with same name (poc-api:myvalue), one with label "Development", the other with no label.

With this code :

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args).ConfigureAppConfiguration((hostingContext, config) =>
            {
                var settings = config.Build();
                config.AddAzureAppConfiguration(options =>
                {
                    options.Connect(settings["ConnectionStrings:AppConfiguration"])
                        .Use(KeyFilter.Any, LabelFilter.Null)
                        .Use(KeyFilter.Any, "Development")
                        .UseFeatureFlags(optionsff =>
                        {
                            optionsff.PollInterval = new TimeSpan(0, 0, 5);
                        }); 
                    options.Watch("poc-api:myvalue",new TimeSpan(0,0,5));
                    
                }); ;
            })
            .UseStartup<Startup>();

It seems I cannot get the value for the key with label "Development", i always get the one without the label

using

<PackageReference Include="Microsoft.Extensions.Configuration.AzureAppConfiguration" Version="1.0.0-preview-008920001-990" />

Code "Inspired" by
https://docs.microsoft.com/en-us/azure/azure-app-configuration/howto-best-practices

from appconfiguration.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.