-
-
Save justinyoo/6ad2999dfc9163b25c3064120e3c079f to your computer and use it in GitHub Desktop.
Adding YAML Settings into ASP.NET Core Apps
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
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