Home > Net >  Is it possible to map/rename keys loaded from Azure App Configuration?
Is it possible to map/rename keys loaded from Azure App Configuration?

Time:09-30

I want to use both appsettings.json and Azure App Configuration to provide configuration for my application. Azure App Configuration will be used by several applications and it is going to be handled via prefixes like AppName1:Auth:ApiKey. However, part of this configuration will be kept in json file like

"Auth" : {
   "Duration": "00:10:00"
}

As it is written here, these settings can't be fetched via single section as they have different key grouping:

  • AppName1:Auth - Azure App Cofniguration
  • Auth - appsettings.json

I would like to have this key grouping AppName1:Auth mapped to Auth, but I'm not sure how to handle this.

I knot that I can change appsettings.json file to

"AppName1" : {
   "Auth" : {
      "Duration": "00:10:00"
   }
}

However, this is something what I want to avoid. And Azure App Configuration per application is also not a solution. Is it possible?

CodePudding user response:

So there is a method to do this:

.ConfigureAppConfiguration((context, builder) =>
{
    builder.AddAzureAppConfiguration(options => options.TrimKeyPrefix("AppName1:"));
})

All credits to my workmate!

  • Related