Samhammer.Configuration.Childs 6.0.0

.NET Standard 2.0
dotnet add package Samhammer.Configuration.Childs --version 6.0.0
NuGet\Install-Package Samhammer.Configuration.Childs -Version 6.0.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="Samhammer.Configuration.Childs" Version="6.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Samhammer.Configuration.Childs --version 6.0.0
#r "nuget: Samhammer.Configuration.Childs, 6.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Samhammer.Configuration.Childs as a Cake Addin
#addin nuget:?package=Samhammer.Configuration.Childs&version=6.0.0

// Install Samhammer.Configuration.Childs as a Cake Tool
#tool nuget:?package=Samhammer.Configuration.Childs&version=6.0.0

Samhammer.Configuration.Childs

Usage

How to add this to your project:

To add it to ASP.NET Core configuration simply place .EnableChildSubstitutions() last. Make sure it is always called after all other configurations are added, else it won't behave properly!

public static IHostBuilder CreateHostBuilder(string[] args) =>
   Host.CreateDefaultBuilder(args)
      .ConfigureAppConfiguration((ctx, builder) =>
      {
          // if you have any additional configuration place it before
          var customer = Environment.GetEnvironmentVariable("CUSTOMER");
          builder.EnableChildSubstitutions(customer);
      });

Set enviroment variable 'Customer' to control which child substitutions are loaded in the configuration. For local development you can do set in launchsettings.json.

"environmentVariables": {
  "ASPNETCORE_ENVIRONMENT": "Development",
  "CUSTOMER": "customer1"
}
When to use it

If you want to deploy multiple production systems (e.g. different customers) and you don´t want to add additional appsettings.json files or additional enviroment variables for all of your settings.

How to use it
Simple Example

Example where the entry ConnectionString in appsettings.json has some default value and some substitutions values for different customers.

{
  "ConnectionString ": "blabla&catalog=myapp",
  "customer1:ConnectionString ": "blabla&catalog=myapp-customer1",
  "customer2:ConnectionString ": "blabla&catalog=myapp-customer2",
}
var value = configuration["ConnectionString"];

This will return 'blabla&catalog=myapp-customer1'.

Additional examples
{
  "DatabaseOptions ": {
    "HostName": "host",
    "CatalogName": "db",
    "UserName": "user"
  },
  "customer1:DatabaseOptions": {
    "CatalogName": "db1",
    "UserName": "user1"  
  }
}
{
  "DatabaseOptions ": {
    "HostName": "host",
    "CatalogName": "db",
    "UserName": "user",
    
    "customer1": {
      "CatalogName": "db1",
      "UserName": "user1"  
    }
  }
}

Contribute

How to publish package
  • Create a tag and let the github action do the publishing for you
Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48 net481
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
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
6.0.0 5,054 1/20/2022
3.1.0 6,334 8/21/2020