-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppSettingsService.cs
38 lines (30 loc) · 1.15 KB
/
AppSettingsService.cs
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
namespace ExampleWebApp.Backend.WebApi;
public static partial class Extensions
{
/// <summary>
/// setup loading of configuration from appsettings.json (mandatory), appsettings.[Environment].json (optional)
/// with autoreload on change ; add configuration from either user-secrets (development) and
/// from environment variables ( replacing : with __ )
/// </summary>
public static void SetupAppSettings(this IConfigurationBuilder config, string environmentName)
{
var appsettingsBase = Path.Combine(
AppDomain.CurrentDomain.BaseDirectory,
"appsettings.json");
var appsettingsEnv = Path.Combine(
AppDomain.CurrentDomain.BaseDirectory,
$"appsettings.{environmentName}.json");
config
.AddJsonFile(
appsettingsBase,
optional: false,
reloadOnChange: true)
.AddJsonFile(
appsettingsEnv,
optional: true,
reloadOnChange: true)
.AddEnvironmentVariables()
.AddUserSecrets(Assembly.GetExecutingAssembly())
;
}
}