Namh.Configuration.Template
1.0.2
dotnet add package Namh.Configuration.Template --version 1.0.2
NuGet\Install-Package Namh.Configuration.Template -Version 1.0.2
<PackageReference Include="Namh.Configuration.Template" Version="1.0.2" />
<PackageVersion Include="Namh.Configuration.Template" Version="1.0.2" />
<PackageReference Include="Namh.Configuration.Template" />
paket add Namh.Configuration.Template --version 1.0.2
#r "nuget: Namh.Configuration.Template, 1.0.2"
#:package Namh.Configuration.Template@1.0.2
#addin nuget:?package=Namh.Configuration.Template&version=1.0.2
#tool nuget:?package=Namh.Configuration.Template&version=1.0.2
TemplateConfig
TemplateConfig resolves {Path} references in .NET configuration values. Install the Namh.Configuration.Template package, register your usual providers, and call BuildTemplateConfig():
dotnet add package Namh.Configuration.Template --version 1.0.2
using Microsoft.Extensions.Configuration;
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json") // Support for JSON files
.AddEnvironmentVariables() // Support for environment variables
.BuildTemplateConfig(); // Return IConfigurationRoot with resolved references
BuildTemplateConfig() returns an IConfigurationRoot, so existing configuration APIs such as indexers, GetSection(), GetChildren(), and Reload() continue to work while referenced values are resolved when read. The Get<T>() extension reads and binds a typed value from a configuration section.
Version 1.0.2 supports .NET 8, .NET 9, and .NET 10.
The examples below use appsettings.json.
Examples
1. Look up
References can point into parent and sibling fields recursively:
{
"Primitive": "Pri", // -> Result: "Pri"
"Ref-Primitive1": "--{Primitive}--", // -> Result: "--Pri--"
"Ref-Primitive2": "{Primitive}.{Ref-Primitive1}", // -> Result: "Pri.--Pri--"
"Ref-Primitive-Loop": "--{{Primitive}mitive}--", // -> Result: "--Pri--"
"Array": [ "A", "B", "{Primitive}" ], // -> Result: [ "A", "B", "Pri" ]
"Root": {
"Field1": "F1",
"Field2": "{Primitive}",
"Child": {
"Field1": "{Root:Field1}",
"Field2": "-{Root:Field1}:{Root:Field2}-"
}
},
}
var value = configuration["Ref-Primitive-Loop"] // -> Result: "--Pri--"
Use Get<T>() to bind a resolved value to a .NET type:
var values = configuration.Get<string[]>("Ref-Array");
// -> Result: [ "1", "2", "--Pri--" ]
Sections resolve referenced values through their indexer and child sections:
var field = configuration.GetSection("Root:Child")["Field2"];
// -> Result: "-F1:Pri-"
2. Escape a character
Use a backtick to keep braces literal:
{
"Primitive": "Pri",
"Escaped": "--`{Primitive`}--"
}
Escaped resolves to --{Primitive}--.
3. Error syntax
An unmatched brace throws InvalidOperationException when the value is read:
{
"MissingClose": "--{Primitive--",
"MissingOpen": "--Primitive}--"
}
Build and test
dotnet build src/TemplateConfig.slnx
dotnet test src/TemplateConfig.slnx
The Release test run currently passes 41 tests for each supported target framework:
net8.0, net9.0, and net10.0.
Create the NuGet package
Run the following command from the repository root to create the release package:
dotnet pack src/Namh.Configuration.Template/Namh.Configuration.Template.csproj --configuration Release --output ./artifacts
The package is written to artifacts/Namh.Configuration.Template.1.0.2.nupkg.
| Product | Versions 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 is compatible. 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. |
-
net10.0
- Microsoft.Extensions.Configuration.Binder (>= 10.0.0)
-
net8.0
- Microsoft.Extensions.Configuration.Binder (>= 10.0.0)
-
net9.0
- Microsoft.Extensions.Configuration.Binder (>= 10.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Namh.Configuration.Template:
| Package | Downloads |
|---|---|
|
Namh.Configuration.GlobalTemplate
Integrates configuration templates with .NET generic hosts and ASP.NET Core applications, resolving references between values in Microsoft.Extensions.Configuration. |
GitHub repositories
This package is not used by any popular GitHub repositories.