0
votes

I'm working on exploring the following 2 features of Azure App Configuration in Azure Function's Http Trigger

  1. Externalizing the App Settings
  2. Feature Flags

Below is how i'm getting the reference of the configuration

enter image description here

So, when I use _configuration["SomeAppSettingKey"], I'm able to retrieve the value. So, I'm able to achieve #1 feature mentioned above.

My Question is, How do we retrieve the Feature Flag information? I have tried the below ways.

enter image description here

I would appreciate if someone could help me in understanding how to retrieve it in Azure Functions (I'm using V3)? A Sample code or any reference to documentation would be helpful.

Thanks.

Update1: I can deserialize the json content as shown below. But, is this is the right approach?

enter image description here

Where FeatureManager is a class that I have defined as shown below.

enter image description here

2
are you saying _configuration["appconfig.featureflag/TurnOnGreeting"] is not working?allen
It returns me a json. But, Is that the best way to access the Feature flags?Prawin
i'm able to de-serialize the json content. I have updated the same in the questionPrawin

2 Answers

1
votes

all you need is to call UseFeatureFlags() function as part of AddAzureAppConfiguration to let the App Configuration provider know you want to use feature flags. An example can be found following the link below. It uses the FunctionsStartup and dependency injection (DI) of Azure Functions. An instance of a feature manager is put into the DI.

https://github.com/Azure/AppConfiguration/blob/master/examples/DotNetCore/AzureFunction/FunctionApp/Startup.cs

The link below shows how you can obtain the instance of IFeatureManagerSnapshot from DI and use it as part of your Azure Functions call.

https://github.com/Azure/AppConfiguration/blob/master/examples/DotNetCore/AzureFunction/FunctionApp/ShowBetaFeature.cs

-1
votes

Deserialize JSON is not a good idea, every time you will add new key you need to modify your class.

private static IConfiguration Configuration { set; get; }

static Function1()
{
    var builder = new ConfigurationBuilder();
    builder.AddAzureAppConfiguration(Environment.GetEnvironmentVariable("ConnectionString"));
    Configuration = builder.Build();
}

public static async Task<IActionResult> Run(
    [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log)
{
    log.LogInformation("C# HTTP trigger function processed a request.");

    string keyName = "TestApp:Settings:Message";
    string message = Configuration[keyName];

    return message != null
        ? (ActionResult)new OkObjectResult(message)
        : new BadRequestObjectResult($"Please create a key-value with the key '{keyName}' in App Configuration.");
}