Created
March 12, 2021 13:59
-
-
Save bjornmicallef/fd9e38a02703c0da3aafe44840f78675 to your computer and use it in GitHub Desktop.
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
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var cfg = InitSettings<AppConfig>(); | |
var loggingUrl = cfg.Logging.Url; | |
var loggingUsername = cfg.Logging.Username; | |
var corsAllowedMethods = cfg.CorsAllowedMethods; | |
Console.WriteLine($"{loggingUrl} {loggingUsername} {corsAllowedMethods}"); | |
Console.ReadKey(); | |
} | |
private static T InitSettings<T>() where T : new() | |
{ | |
var config = InitConfig(); | |
return config.Get<T>(); | |
} | |
private static IConfigurationRoot InitConfig() | |
{ | |
// load setup file name and path from appsettings.json | |
var builder = new ConfigurationBuilder() | |
.AddJsonFile($"appsettings.json", true, true) | |
.AddEnvironmentVariables(); | |
return builder.Build(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment