Created
February 2, 2020 15:20
-
-
Save kasunkv/e485a9ec42a67954da00df5b17736f8d to your computer and use it in GitHub Desktop.
Configure dynamic refresh for Azure App Configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Azure.Identity; | |
using Microsoft.Extensions.Configuration.AzureAppConfiguration; | |
namespace MusicStore.Web | |
{ | |
public class Program | |
{ | |
.. | |
public static IHostBuilder CreateHostBuilder(string[] args) => | |
Host.CreateDefaultBuilder(args) | |
.ConfigureWebHostDefaults(webBuilder => { | |
webBuilder.UseStartup<Startup>(); | |
}) | |
.ConfigureAppConfiguration((context, config) => { | |
var settings = config.Build(); | |
var appConfigEndpoint = settings["AppSettings:AppConfiguration:Endpoint"]; | |
var userAssignedIdentityClientId = settings["AppSettings:Identity:ClientId"]; | |
if (!string.IsNullOrEmpty(appConfigEndpoint)) | |
{ | |
var endpoint = new Uri(appConfigEndpoint); | |
config.AddAzureAppConfiguration(options => | |
{ | |
options | |
.Connect(endpoint, new ManagedIdentityCredential(clientId: userAssignedIdentityClientId)) | |
// Setting up dynamic app configuration | |
.ConfigureRefresh(refreshOpt => | |
{ | |
refreshOpt.Register(key: "AppSettings:Version", refreshAll: true, label: LabelFilter.Null); | |
}) | |
.UseFeatureFlags(); | |
}); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment