TemplatedConfiguration 0.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package TemplatedConfiguration --version 0.2.0                
NuGet\Install-Package TemplatedConfiguration -Version 0.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="TemplatedConfiguration" Version="0.2.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TemplatedConfiguration --version 0.2.0                
#r "nuget: TemplatedConfiguration, 0.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 TemplatedConfiguration as a Cake Addin
#addin nuget:?package=TemplatedConfiguration&version=0.2.0

// Install TemplatedConfiguration as a Cake Tool
#tool nuget:?package=TemplatedConfiguration&version=0.2.0                

Templated Configuration Source for Microsoft.Extensions.Configuration Build Status

This library is an extension for Microsoft.Extensions.Configuration, which helps you to do recursive templating in configuration settings.

When retrieving a configuration setting value, it will look for {placeholders}. If it finds any placeholder, it will try to see if the placeholder is actually configured as a setting. It will then (recursively) replace any placeholders within the setting's value.

This means you can compose configuration settings out of other configuration settings, which will allow you to override only parts of a config setting or the entire setting.

Example use cases.

For my settings, I like to use smart defaults and compose other settings from these smart defaults.

For example, often when I have multiple components that require a database connection, then most of these components can use the same connection string. But I like to use default database names, so the only thing I really want to be 'forced' to configure is the server name. But, I still want the capability to override individual parts of the settings if I really choose to.

Another example is when accessing an URL from code, where the URL is usually composed of a 'base path' and a route. I want to use smart defaults, but retain the capability to override them if I need to.

Getting Started

  • Add a reference to TemplatedConfiguration

  • Add a using statement to 'TemplatedConfiguration'

  • Wrap the normal 'configuration builder' with a templated support builder, preferably by using the WithRecursiveTemplateSupport Extension method.


    using TemplatedConfiguration;

    /* snip ... */

        var config = new ConfigurationBuilder()
                // First set up defaults, for example using in memory
                .AddInMemoryCollection(Global.DefaultSettings)

                // Then set up the 'overrides'. 
                .AddIniFile("Config.ini")
                .AddCommandLine(args)
                .AddEnvironmentVariables()

                // Wrap the configuration providers with the provider that supports templating
                .WithRecursiveTemplateSupport()

                // Any provider added after this will NOT partake in the templating. 
            .Build();

Licencing

Licenced under MIT.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  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 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
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.0.1 65,632 11/20/2018
1.0.0 1,151 11/19/2018
0.2.0 1,152 11/15/2018
0.1.0 1,171 11/13/2018

Adds support for configuration sections (separated by :) character