Appconfiguration: Would it be possible to remove prefixes upon configuration bind?

Created on 29 Apr 2019  路  5Comments  路  Source: Azure/AppConfiguration

config.AddAzureAppConfiguration(options => { options.ConnectWithManagedIdentity(appConfigEndpoint) .Use("AppName:Service1:*","Production") .WatchAndReloadAll("AppName:Service1:Trigger", "Production", watchPolingInterval) .RemovePrefix("AppName:Service1"); });

.RemovePrefix or something similar is what I am suggesting. Basically to bind the retrieved settings without the prefix so that AzureAppConfiguration automatically overrides appsettings.json and appsettings.[Environment].json

Without this 'RemovePrefix' functionality, several changes will need to be done to support both loading from appsettings and Azure App Configuration.

This is a make or break for us.

.NET Config Provider

Most helpful comment

All 5 comments

@TheReaLee, I think this is a good suggestion. Thanks!

I am thinking of an API something like this

UsePrefix(string keyPrefix, string labelFilter)

Unlike keyFilter, anything specified as "prefix" will be stripped out automatically (it will still do the filtering). So in your example, the code will look like

config.AddAzureAppConfiguration(options => { 
  options.ConnectWithManagedIdentity(appConfigEndpoint) 
    .UsePrefix("AppName:Service1:","Production") 
    .WatchAndReloadAll("AppName:Service1:Trigger", "Production", watchPolingInterval);
});

After some discussion with @drago-draganov, he convinced me a dedicated API to remove the prefix is actually a better idea (@TheReaLee's original suggestion 馃憤).

  • It can be called multiple times in the chain to remove different prefixes
  • Decoupling the key filtering and the prefix to trim provides better flexibility

Here is the proposed API

public AzureAppConfigurationOptions TrimKeyPrefix(string prefix)

@zhenlan sounds perfect! Thanks for looking into it.
When are you planning to release it?

@TheReaLee, there are a few other changes I'd like to have before we roll out another release, but this shouldn't take too long.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kamalsivalingam picture kamalsivalingam  路  4Comments

justinmetz picture justinmetz  路  3Comments

kamalsivalingam picture kamalsivalingam  路  6Comments

funkysi1701 picture funkysi1701  路  7Comments

ssulei7 picture ssulei7  路  6Comments