henkmollema / ConfigurationPlaceholders

Placeholder support for the ASP.NET Core Configuration framework.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

License:MIT License


Languages

Language:C# 53.1%Language:PowerShell 26.2%Language:Shell 17.0%Language:Batchfile 3.7%