Managing App Settings made easy with Azure App Configuration

Distributed and micro-services based applications runs on multiple virtual machines or containers. Managing all the configuration settings for the services and components in such systems is a challenge. Spreading configuration settings across these components can lead to hard-to-troubleshoot errors during an application deployment.

Azure App Configuration helps to store all these settings for application centrally and provide secure access. These settings are stored as Key-Value an making a change to one key value cane be updated to all the applications using the setting. App Configuration also provides encryption in transit and at rest, and point-in-time snapshots so to help in comparing settings over time, or rollback settings after a failed deployment.

Create an app configuration store

To create an app configuration, login to the Azure portal.  Search and Select App Configuration from the search results, and then select Create.

appconfig_1

Click, Add button on the top, fill the required details in the new blade and click Create.

appconfig_2

Once your App configuration resource is ready, you’ll find primary and secondary connection strings in Access Keys, like you would in a storage account. You may use “Readonly” Keys for the application to have only read access.

appconfig_3

You can use the Key-Value Explorer to begin adding settings into the configuration store.

appconfig_4

You can also tag a setting, lock a setting, and look at the history of changes for a setting as below.

appconfig_5

The History shows all the changes made to the config key along with the date and time of the change.

appconfig_6

Moreover, you can compare settings with different labels (for eg: Prod vs Staging or Prod vs DR) to view differences.

appconfig_7

Using App Configuration in .Net Console Application

1. Right-click your project, and select Manage NuGet Packages. On the Browse tab, search and add the following NuGet packages to your project. If you can’t find them, select the Include prerelease check box.

Microsoft.Configuration.ConfigurationBuilders.AzureAppConfiguration 1.0.0 preview or later

Microsoft.Configuration.ConfigurationBuilders.Environment 2.0.0 preview or later

2. Update the App.config file of project as below:

<configSections>
<section name=”configBuilders” type=”System.Configuration.ConfigurationBuildersSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a” restartOnExternalChanges=”false” requirePermission=”false” />
</configSections>

<configBuilders>
<builders>
<add name=”MyConfigStore” mode=”Greedy” connectionString=”${ConnectionString}” type=”Microsoft.Configuration.ConfigurationBuilders.AzureAppConfigurationBuilder, Microsoft.Configuration.ConfigurationBuilders.AzureAppConfiguration” />
<add name=”Environment” mode=”Greedy” type=”Microsoft.Configuration.ConfigurationBuilders.EnvironmentConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.Environment” />
</builders>
</configBuilders>

<appSettings configBuilders=”Environment,MyConfigStore”>
<add key=”AppName” value=”Console App Demo” />
<add key=”ConnectionString” value =”Set via an environment variable – for example, dev, test, staging, or production connection string.” />
</appSettings>

The connection string of your app configuration store is read from the environment variable ConnectionString. Add the Environment configuration builder before the MyConfigStore in the configBuilders property of the appSettings section.

3. Open Program.cs, and update the Main method to use App Configuration by calling ConfigurationManager.

static void Main(string[] args)
{
string message = ConfigurationManager.AppSettings[“TestApp:Settings:Message”];
Console.WriteLine(message);
}

 

Also Read Import and export configuration in Azure App Configuration Store

 

Advertisements

Written by Varun Kumar

Varun works with Microsoft as a Cloud Consultant. He comes with 10+ years of experience into Consultant, Solution Architect, and Delivery Management roles. As a Consultant in Microsoft, his job is to design, develop and deploy enterprise level solutions using Azure, to help organizations to achieve more.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s