Skip to content

Instantly share code, notes, and snippets.

@aidangarnish
Created October 23, 2020 15:53
Show Gist options
  • Select an option

  • Save aidangarnish/dfa661b60d4cbf1fd991e181e2f2f504 to your computer and use it in GitHub Desktop.

Select an option

Save aidangarnish/dfa661b60d4cbf1fd991e181e2f2f504 to your computer and use it in GitHub Desktop.
public static class ConfigHelper
{
private static readonly IConfigurationRoot Config;
static ConfigHelper()
{
Config = new ConfigurationBuilder()
.SetBasePath(AppContext.BaseDirectory)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.Build();
}
public static AppConfig AppConfig
{
get
{
AppConfig appConfig = new AppConfig();
Config.Bind(appConfig);
var env = System.Environment.GetEnvironmentVariable("Environment");
appConfig.APIBaseUrl = env.ToLower() == "prod" ? appConfig.APIBaseUrl.Replace("-[env].", "") : appConfig.APIBaseUrl.Replace("[env]", env);
appConfig.APIKey = System.Environment.GetEnvironmentVariable("APIKey");
return appConfig;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment