Workleap.Extensions.Configuration.Substitution
1.1.5
Prefix Reserved
dotnet add package Workleap.Extensions.Configuration.Substitution --version 1.1.5
NuGet\Install-Package Workleap.Extensions.Configuration.Substitution -Version 1.1.5
<PackageReference Include="Workleap.Extensions.Configuration.Substitution" Version="1.1.5" />
paket add Workleap.Extensions.Configuration.Substitution --version 1.1.5
#r "nuget: Workleap.Extensions.Configuration.Substitution, 1.1.5"
// Install Workleap.Extensions.Configuration.Substitution as a Cake Addin #addin nuget:?package=Workleap.Extensions.Configuration.Substitution&version=1.1.5 // Install Workleap.Extensions.Configuration.Substitution as a Cake Tool #tool nuget:?package=Workleap.Extensions.Configuration.Substitution&version=1.1.5
Workleap.Extensions.Configuration.Substitution
This package adds variable substitution configuration provider implementation for Microsoft.Extensions.Configuration.
Getting started
dotnet add package Workleap.Extensions.Configuration.Substitution
// Example for an ASP.NET Core web application
var builder = WebApplication.CreateBuilder(args);
// Setup your configuration
builder.Configuration.AddJsonFile("appsettings.json");
builder.Configuration.AddEnvironmentVariables();
builder.Configuration.AddSubstitution(); // <-- Add this after other configuration providers
How it works
You can reference configuration values inside other configuration values by enclosing the referenced configuration key like this: ${ReferencedConfigurationKey}
.
Examples
Consider this appsettings.json
:
{
"Credentials": {
"Username": "alice1",
"Password": "P@ssw0rd"
},
"ConnectionString": "usr=${Credentials:Username};pwd=${Credentials:Password}"
}
Evaluating the configuration value ConnectionString
would return usr=alice1;pwd=P@ssw0rd
.
This also works if you're using multiple configuration providers. For instance, one could have the Credentials:Password
configuration value provided by a secret from Azure Key Vault and this value would have been injected into the ConnectionString
value too.
It also works with arrays:
{
"Credentials": [ "alice1", "P@ssw0rd" ],
"ConnectionString": "usr=${Credentials:0};pwd=${Credentials:1}"
}
Again, you're not limited to JSON file providers, you could use substitution with any configuration providers. It was easier to use JSON files in these examples.
Escaping values
You might not want a specific value to be substituted. In that case, escape it using double curly braces:
{
"Foo": "foo",
"Bar": "${{Foo}}"
}
Evaluating the configuration value Bar
would return ${Foo}
.
Exceptions
You can encounter two kinds of exceptions if your configuration is incorrect:
UnresolvedConfigurationKeyException
, if you're trying to substitute a configuration value that is undefined (i.e. the key does not exist).RecursiveConfigurationKeyException
, if you have many configuration values that reference each other in a recursive manner, no matter how deep the recursion is. The exception will give you details about the recursive path.
UnresolvedConfigurationKeyException
can also be triggered sooner than later by using AddSubstitution(eagerValidation: true)
. Using eagerValidation
with value true
(default is false
) instructs the library to check for undefined values in all the existing configuration values once, instead of checking for a particular value. This happens as soon as any configuration value is loaded.
Configuration providers order
When using .NET's IConfigurationBuilder, the order of configuration providers matters . Any configuration provider added after AddSubstitution()
would not benefit from the substitution process.
License
Copyright © 2022, Workleap. This code is licensed under the Apache License, Version 2.0. You may obtain a copy of this license at https://github.com/workleap/gsoft-license/blob/master/LICENSE.
Product | Versions 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 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 was computed. 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. |
.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. |
-
.NETStandard 2.0
- Microsoft.Extensions.Configuration (>= 6.0.0)
-
net8.0
- Microsoft.Extensions.Configuration (>= 6.0.0)
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.1.5 | 140 | 3 days ago |
1.1.5-preview.13 | 99 | 3 days ago |
1.1.5-preview.12 | 97 | 3 days ago |
1.1.5-preview.11 | 100 | 3 days ago |
1.1.5-preview.10 | 101 | 4 days ago |
1.1.5-preview.9 | 33 | 9 days ago |
1.1.5-preview.8 | 118 | 12 days ago |
1.1.5-preview.7 | 69 | a month ago |
1.1.5-preview.6 | 67 | a month ago |
1.1.5-preview.5 | 56 | a month ago |
1.1.5-preview.4 | 62 | a month ago |
1.1.5-preview.3 | 63 | a month ago |
1.1.5-preview.2 | 64 | 2 months ago |
1.1.5-preview.1 | 61 | 2 months ago |
1.1.4 | 17,444 | 2 months ago |
1.1.4-preview.16 | 59 | 2 months ago |
1.1.4-preview.15 | 54 | 2 months ago |
1.1.4-preview.13 | 68 | 3 months ago |
1.1.4-preview.12 | 231 | 4 months ago |
1.1.4-preview.11 | 60 | 4 months ago |
1.1.4-preview.10 | 58 | 4 months ago |
1.1.4-preview.9 | 59 | 5 months ago |
1.1.4-preview.8 | 61 | 5 months ago |
1.1.4-preview.7 | 61 | 5 months ago |
1.1.4-preview.6 | 61 | 5 months ago |
1.1.4-preview.5 | 63 | 5 months ago |
1.1.4-preview.4 | 59 | 6 months ago |
1.1.4-preview.3 | 63 | 6 months ago |
1.1.4-preview.2 | 63 | 6 months ago |
1.1.4-preview.1 | 72 | 6 months ago |
1.1.3 | 31,172 | 6 months ago |
1.1.3-preview.48 | 67 | 6 months ago |
1.1.3-preview.47 | 68 | 6 months ago |
1.1.3-preview.46 | 66 | 7 months ago |
1.1.3-preview.45 | 62 | 7 months ago |
1.1.3-preview.44 | 65 | 7 months ago |
1.1.3-preview.43 | 60 | 7 months ago |
1.1.3-preview.42 | 78 | 7 months ago |
1.1.3-preview.41 | 63 | 8 months ago |
1.1.3-preview.40 | 84 | 8 months ago |
1.1.3-preview.39 | 65 | 8 months ago |
1.1.3-preview.38 | 59 | 9 months ago |
1.1.3-preview.37 | 69 | 10 months ago |
1.1.3-preview.36 | 66 | 10 months ago |
1.1.3-preview.35 | 68 | 5/21/2024 |
1.1.3-preview.34 | 75 | 5/10/2024 |
1.1.3-preview.33 | 65 | 5/3/2024 |
1.1.3-preview.32 | 134 | 4/15/2024 |
1.1.3-preview.31 | 88 | 4/12/2024 |
1.1.3-preview.30 | 77 | 4/3/2024 |
1.1.3-preview.29 | 78 | 4/3/2024 |
1.1.3-preview.28 | 76 | 3/8/2024 |
1.1.3-preview.27 | 77 | 3/7/2024 |
1.1.3-preview.26 | 76 | 3/4/2024 |
1.1.3-preview.25 | 82 | 3/1/2024 |
1.1.3-preview.24 | 82 | 2/16/2024 |
1.1.3-preview.23 | 77 | 2/12/2024 |
1.1.3-preview.22 | 90 | 2/6/2024 |
1.1.3-preview.21 | 77 | 2/6/2024 |
1.1.3-preview.20 | 78 | 1/22/2024 |
1.1.3-preview.19 | 76 | 1/12/2024 |
1.1.3-preview.18 | 72 | 1/12/2024 |
1.1.3-preview.17 | 70 | 1/12/2024 |
1.1.3-preview.16 | 94 | 12/18/2023 |
1.1.3-preview.15 | 110 | 11/26/2023 |
1.1.3-preview.14 | 96 | 11/17/2023 |
1.1.3-preview.13 | 79 | 11/13/2023 |
1.1.3-preview.12 | 159 | 11/6/2023 |
1.1.3-preview.11 | 93 | 10/30/2023 |
1.1.3-preview.10 | 93 | 10/20/2023 |
1.1.3-preview.9 | 94 | 10/17/2023 |
1.1.3-preview.8 | 95 | 10/13/2023 |
1.1.3-preview.7 | 93 | 9/26/2023 |
1.1.3-preview.6 | 88 | 9/25/2023 |
1.1.3-preview.5 | 81 | 9/21/2023 |
1.1.3-preview.4 | 84 | 9/20/2023 |
1.1.3-preview.3 | 87 | 9/20/2023 |
1.1.3-preview.2 | 84 | 9/20/2023 |
1.1.3-preview.1 | 100 | 8/9/2023 |
1.1.2 | 98,527 | 7/20/2023 |
1.1.2-preview.20 | 99 | 7/20/2023 |