-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathProgram.cs
More file actions
52 lines (41 loc) · 1.73 KB
/
Program.cs
File metadata and controls
52 lines (41 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
//
using Azure.Identity;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Microsoft.Extensions.Configuration.AzureAppConfiguration.Examples.ConsoleApplicationWithFailOver
{
class Program
{
static IConfiguration? Configuration { get; set; }
static void Main(string[] args)
{
Configure();
Console.WriteLine($"The AppName is: {Configuration?["AppName"]}.");
}
private static void Configure()
{
var builder = new ConfigurationBuilder();
// Load a subset of the application's configuration from a json file and environment variables
builder.AddJsonFile("appsettings.json")
.AddEnvironmentVariables();
IConfiguration configuration = builder.Build();
IConfigurationSection endpointsSection = configuration.GetSection("AppConfig:Endpoints");
IEnumerable<Uri> endpoints = endpointsSection.GetChildren().Select(endpoint => new Uri(endpoint.Value!));
if (endpoints == null || !endpoints.Any())
{
Console.WriteLine("Endpoints not found.");
Console.WriteLine("Please set the array 'Appconfig:Endpoints' in appsettings.json with valid Azure App Configuration replica endpoints and re-run this example.");
return;
}
// Augment the configuration builder with Azure App Configuration
builder.AddAzureAppConfiguration(options =>
{
options.Connect(endpoints, new DefaultAzureCredential());
});
Configuration = builder.Build();
}
}
}