Skip to content
This repository has been archived by the owner on Nov 23, 2018. It is now read-only.

Placeholder support for the ASP.NET Core Configuration framework.

License

Notifications You must be signed in to change notification settings

henkmollema/ConfigurationPlaceholders

Repository files navigation

Configuration Placeholders

Placeholder support for the ASP.NET Core Configuration framework.

Usage

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/

Samples

Check out the sample web app for more details.

About

Placeholder support for the ASP.NET Core Configuration framework.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published