-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathSettings.cs
More file actions
35 lines (27 loc) · 1.09 KB
/
Settings.cs
File metadata and controls
35 lines (27 loc) · 1.09 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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
// cSpell:ignore appsettings
// <SettingsSnippet>
using Microsoft.Extensions.Configuration;
namespace GraphTutorial;
public class Settings
{
public string? ClientId { get; set; }
public string? TenantId { get; set; }
public string[]? GraphUserScopes { get; set; }
public static Settings LoadSettings()
{
// Load settings
IConfiguration config = new ConfigurationBuilder()
/* appsettings.json is required */
.AddJsonFile("appsettings.json", optional: false)
/* appsettings.Development.json" is optional, values override appsettings.json */
.AddJsonFile($"appsettings.Development.json", optional: true)
/* User secrets are optional, values override both JSON files */
.AddUserSecrets<Program>()
.Build();
return config.GetRequiredSection("Settings").Get<Settings>() ??
throw new Exception("Could not load app settings. See README for configuration instructions.");
}
}
// </SettingsSnippet>