avatarAshish Patel

Summary

This context provides instructions on how to use Azure App Configuration with .NET or ASP.NET Core applications.

Abstract

The context discusses the use of Azure App Configuration for storing and managing application settings for .NET or ASP.NET Core applications. It explains the benefits of using Azure App Configuration, such as centralizing storage and management of application settings, and the ability to share settings among multiple apps. The context also provides step-by-step instructions on how to enable the use of Azure App Configuration in an ASP.NET Core application, including installing required packages, modifying Host Builder logic, and enabling automatic configuration refresh from Azure App Configuration. The context also includes code snippets and screenshots to illustrate the process.

Bullet points

  • Azure App Configuration allows for centralized storage and management of application settings for .NET or ASP.NET Core applications.
  • To enable the use of Azure App Configuration, required packages need to be installed.
  • Host Builder logic needs to be modified to add the code needed for Azure App Configuration.
  • Automatic configuration refresh from Azure App Configuration can be enabled in Startup.cs.
  • Connection string for Azure App Configuration needs to be stored in the appsettings.json file.
  • Azure App Configuration connection string can be obtained from the Azure Portal.
  • Settings can be read in Controller using Azure App Configuration.
  • Sample source code is available on GitHub.

Use Azure App Configuration with .NET or ASP.NET Core Applications

Store app settings in Azure App Configuration for .NET 5.x or ASP.NET Core 3.x applications.

Azure App Configuration

TL;DR

Azure App Configuration allows you to define settings that can be shared among multiple apps, including apps running in App Service. We will use Azure App Configuration to centralize storage and management of application settings for an ASP.NET Core application. ASP.NET Core builds a single key-value-based configuration object using settings from one or more data sources specified by an application.

More details on Azure App Configuration Use Azure Key Vault with .NET or ASP.NET Core Applications

Store settings in Azure App Configuration

To enable the use of Azure App Configuration you need to install below packages.

PM> Install-Package Microsoft.Azure.AppConfiguration.AspNetCore
PM> Install-Package Microsoft.FeatureManagement.AspNetCore
PM> Install-Package Azure.Identity

You need to modify your Host Builder logic to add the code needed. We can use the ConfiureAppConfiguration() method to plug in Azure App Configuration code into ASP.NET Core Application configuration.

  1. Enable App Configuration in Program.cs — Update the CreateWebHostBuilder method to use App Configuration by calling the config.AddAzureAppConfiguration() method.

2. Enable automatic configuration refresh from Azure App Configuration in Startup.cs.

3. Store connection string in the appsettings.json file.

4. Get Azure App Configuration Connection String from Azure Portal

Azure Portal — Azure App Configuration Connection Strings

5. Read settings in Controller.

Sample source code on GitHub.NET 5.x and ASP.NET Core 3.x

View more from .NET Hub

Happy Coding!!!

Microsoft
Azure
Aspnetcore
App Configuration
Azure Key Vault
Recommended from ReadMedium