Skip to content

Instantly share code, notes, and snippets.

@justinyoo
Last active January 25, 2017 05:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinyoo/6ad2999dfc9163b25c3064120e3c079f to your computer and use it in GitHub Desktop.
Save justinyoo/6ad2999dfc9163b25c3064120e3c079f to your computer and use it in GitHub Desktop.
Adding YAML Settings into ASP.NET Core Apps
public class Startup
{
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath);
// Adds JSON settings first
builder.AddJsonFile("appsettings.json", optional: true, adOnChange: true);
builder.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
// Adds YAML settings later
builder.AddYamlFile("appsettings.yml", optional: true);
// Adds Secret settings (in JSON format)
if (env.IsDevelopment)
{
builder.AddUserSecrets();
}
// Adds environment variables
builder.AddEnvironmentVariables();
this.Configuration = builder.Build();
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment