PetToys.TemplatedConfigurationProvider 1.2.0

Prefix Reserved
dotnet add package PetToys.TemplatedConfigurationProvider --version 1.2.0                
NuGet\Install-Package PetToys.TemplatedConfigurationProvider -Version 1.2.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PetToys.TemplatedConfigurationProvider" Version="1.2.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PetToys.TemplatedConfigurationProvider --version 1.2.0                
#r "nuget: PetToys.TemplatedConfigurationProvider, 1.2.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install PetToys.TemplatedConfigurationProvider as a Cake Addin
#addin nuget:?package=PetToys.TemplatedConfigurationProvider&version=1.2.0

// Install PetToys.TemplatedConfigurationProvider as a Cake Tool
#tool nuget:?package=PetToys.TemplatedConfigurationProvider&version=1.2.0                

Templated configuration provider

Unit Test NuGet Version NuGet Downloads

Features

This library adds its own ConfigurationProvider to the configuration builder. This provider can override values from previously registered providers. New values are computed according to the template (if defined).

  • Absolute references to values are supported.
  • Relative links from the same or parent sections are supported.
  • Configuration reload are supported (IOptionMonitor<>).

Template examples

Configuration:

{
  "ConnectionStrings": {
    "DbConnection1": "Host=localhost;Password={ConnectionStrings:DbConnection:Password};",
    "DbConnection2": "Host=localhost;Password={DbConnection:Password};",
    "DbConnection:Password": "Pa$Sw0{rD"
  }
}

Result:

{
  "ConnectionStrings": {
    "DbConnection1": "Host=localhost;Password=Pa$Sw0{rD;",
    "DbConnection2": "Host=localhost;Password=Pa$Sw0{rD;",
    "DbConnection:Password": "Pa$Sw0{rD"
  }
}

More examples in unit tests.

Getting started

  • Provider is installed from NuGet. dotnet add package PetToys.TemplatedConfigurationProvider
  • Add a using statement to PetToys.TemplatedConfigurationProvider
  • Add a provider to the configuration builder, preferably by using the AddTemplatedConfiguration() extension method.

Examples of using

using PetToys.TemplatedConfigurationProvider;

/* snip ... */

    IConfigurationRoot configuration = new ConfigurationBuilder()
        .AddJsonFile("appsettings.json")
        .AddUserSecrets(Assembly.GetExecutingAssembly())
        .AddEnvironmentVariables()
        .AddTemplatedConfiguration()
        .AddCommandLine(args)
        .Build();
using PetToys.TemplatedConfigurationProvider;

/* snip ... */

    var builder = WebApplication.CreateBuilder(args);
    builder.Configuration.AddTemplatedConfiguration(opt =>
    {
        opt.TemplateCharacterStart = '[';
        opt.TemplateCharacterEnd = ']';
    });

Provided under the Apache License, Version 2.0.

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.0 132 11/16/2024
1.1.2 3,349 4/16/2024
1.1.1 114 4/16/2024
1.1.0 8,894 11/14/2023
1.0.1 1,766 7/10/2023
1.0.0 353 7/4/2023
1.0.0-rc1 147 7/3/2023

- added support net9
- some improvements
- out of support net6