Created
November 17, 2019 14:19
-
-
Save msajid/8b8f51e4927c4f86835c9e6a05169c18 to your computer and use it in GitHub Desktop.
Azure App Configuration in a .NET Core Console App
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 Microsoft.Azure.KeyVault; | |
using Microsoft.Azure.Services.AppAuthentication; | |
using Microsoft.Extensions.Configuration; | |
using Microsoft.Extensions.Configuration.AzureAppConfiguration; | |
using System; | |
using System.Threading.Tasks; | |
namespace AppConfigConsoleDemo | |
{ | |
class Program | |
{ | |
static async Task Main(string[] args) | |
{ | |
IConfigurationRefresher refresher = null; | |
IConfiguration configuration = null; | |
var builder = new ConfigurationBuilder(); | |
builder.AddAzureAppConfiguration(options => | |
{ | |
options | |
.ConnectWithManagedIdentity("https://abc1234configstore.azconfig.io") | |
.ConfigureRefresh(refresh => | |
{ | |
refresh | |
.Register("test", refreshAll: true) | |
.SetCacheExpiration(TimeSpan.FromSeconds(1)); | |
}); | |
refresher = options.GetRefresher(); | |
}); | |
configuration = builder.Build(); | |
PrintConfig(configuration); | |
await refresher.Refresh(); | |
PrintConfig(configuration); | |
} | |
static void PrintConfig(IConfiguration configuration) | |
{ | |
Console.WriteLine("_______________________________________________"); | |
foreach (var configItem in configuration.AsEnumerable()) | |
{ | |
Console.WriteLine($"Key {configItem.Key} -> Value {configItem.Value}"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment