TemplatedConfiguration 0.1.0

Package Description

There is a newer version of this package available.
See the version list below for details.
Install-Package TemplatedConfiguration -Version 0.1.0
dotnet add package TemplatedConfiguration --version 0.1.0
<PackageReference Include="TemplatedConfiguration" Version="0.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TemplatedConfiguration --version 0.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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.

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.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.1 243 11/20/2018
1.0.0 141 11/19/2018
0.2.0 128 11/15/2018
0.1.0 146 11/13/2018