ParametrizedConfiguration 1.2.0

dotnet add package ParametrizedConfiguration --version 1.2.0
                    
NuGet\Install-Package ParametrizedConfiguration -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="ParametrizedConfiguration" Version="1.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ParametrizedConfiguration" Version="1.2.0" />
                    
Directory.Packages.props
<PackageReference Include="ParametrizedConfiguration" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ParametrizedConfiguration --version 1.2.0
                    
#r "nuget: ParametrizedConfiguration, 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.
#:package ParametrizedConfiguration@1.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ParametrizedConfiguration&version=1.2.0
                    
Install as a Cake Addin
#tool nuget:?package=ParametrizedConfiguration&version=1.2.0
                    
Install as a Cake Tool

ParametrizedConfiguration

An ASP .NET Core class library presents a configuration provider that uses either it`s own configuration data via other providers or environment variables to parametrize parameter placeholders with values, accessed by parameter keys. By default placeholders defined between two % symbols like %param name%, where param name should be either the key of the same configuration or environment variable name, the value of which will be substituted into %param name%.

For example, this configuration described as a json:

{
  "param1": "1+%param2%",
  "param2": "2+%param3%",
  "param3": "3"
}

will be parametrized into this:

{
  "param1": "1+2+3",
  "param2": "2+3",
  "param3": "3"
}

We also may use environment variables over configuration parameters:

Environment.SetEnvironmentVariable("param3", "?");
{
  "param1": "1+2+?",
  "param2": "2+?",
  "param3": "3"
}

This can be used to hide sensitive data from publicly stored configurations or to reuse the same values in different parts of the configuration.

NuGet NuGet

Installation:

  • from NuGet;
  • from package manager console:
Install-Package ParametrizedConfiguration
  • from command line:
dotnet add package ParametrizedConfiguration

Usage:

Parametrization will be made on any configuration that registered ParametrizedConfigurationProvider. The registration is made by calling WithParametrization() extension method on configuration builder.

Call WithParametrization() method last before you build your configuration as it uses all providers registered before itself.

var configuration = new ConfigurationBuilder()
    // ...Here will be listed all configuration providers (at least one)...
    .WithParametrization() // Parametrized provider registered here as last one
    .Build();

Examples:

Here is a simple example to demonstrate configuration parametrization:

using Microsoft.Extensions.Configuration;
using ConfigurationRepository;

// Assume secrets are set via environment variables somewere outside this code,
// we set them here just for clarity.
Environment.SetEnvironmentVariable("UserName", "Bob");
Environment.SetEnvironmentVariable("Password", "strongPassword");

// Let`s define our simple configuration with parameters using in-memory configuration.
// In production code we will store our configuration in json files or other sources.
Dictionary<string, string?> inMemoryDict = new()
{

    {
        "DatabaseName",
        "MyDatabase"
    },
    {
        "ConnectionStrings:Mssql",
        "Server=mssql-server;Database=%DatabaseName%;User Id=%UserName%;Password=%Password%;TrustServerCertificate=True"
    }
};

// Define that configuration with parametrization provider:
var configuration = new ConfigurationBuilder()
    .AddInMemoryCollection(inMemoryDict)
    .WithParametrization()
    .Build();

// Ok, now let`s get the connection string from configuration:
Console.WriteLine(configuration.GetConnectionString("mssql"));

// Output will be parametrized with values from both configuration and environment variables:
// Server=mssql-server;Database=MyDatabase;User Id=Bob;Password=strongPassword;TrustServerCertificate=True

This example you may also find in ParametrizedConfiguration.EnvSecrets sample project on github.

Product Compatible and additional computed target framework versions.
.NET 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.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on ParametrizedConfiguration:

Package Downloads
ConfigurationRepository.Dapper

Configuration repository provider that stored in a database and accessed via Dapper ORM.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.0 95 7/30/2025
1.1.2 136 7/9/2025
1.1.1 136 7/1/2025
1.1.0 126 6/29/2025
1.0.0 158 6/16/2025