-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathProgram.cs
More file actions
47 lines (43 loc) · 1.83 KB
/
Program.cs
File metadata and controls
47 lines (43 loc) · 1.83 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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
//
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using System;
namespace Microsoft.Extensions.Configuration.AzureAppConfiguration.Examples.ConfigStoreDemo
{
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args)
{
return WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostingContext, config) =>
{
// 1. Load settings from a JSON file and Azure App Configuration
// 2. Retrieve the Azure App Configuration connection string from an environment variable
// 3. Set up the provider to listen for changes to the background color key-value in Azure App Configuration
var settings = config.AddJsonFile("appsettings.json").Build();
config.AddAzureAppConfiguration(options =>
{
var connectionString = settings["connection_string"];
if (string.IsNullOrEmpty(connectionString))
{
throw new InvalidOperationException("Connection string not found");
}
options.Connect(connectionString)
.ConfigureRefresh(refresh =>
{
refresh.Register("Settings:BackgroundColor")
.SetCacheExpiration(TimeSpan.FromSeconds(10));
});
});
})
.UseStartup<Startup>()
.Build();
}
}
}