Placeholder support for the ASP.NET Core Configuration framework.
Define placeholdes in your settings file. You can use multiple placeholders inside static strings.
{
"FooService": {
"Endpoint": "http://example.com/api/",
"Resource": "resources/v2/"
},
"BarService": {
"Endpoint": "[FooService:Endpoint]"
},
"BazService": {
"Endpoint": "http://example2.com/api/[ASPNETCORE_ENVIRONMENT]/[FooService:Resource]"
}
}
Build your configuration object and call ReplacePlaceholders()
:
public Startup(IHostingEnvironment env)
{
Configuration = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json")
.AddEnvironmentVariables()
.Build()
.ReplacePlaceholders();
}
private IConfiguration Configuration { get; }
Use the configuration values:
var endpoint = Configuration["BazService:Endpoint"];
// http://example2.com/api/Development/resources/v2/
Check out the sample web app for more details.