Namh.Configuration.Template
1.0.1
See the version list below for details.
dotnet add package Namh.Configuration.Template --version 1.0.1
NuGet\Install-Package Namh.Configuration.Template -Version 1.0.1
<PackageReference Include="Namh.Configuration.Template" Version="1.0.1" />
<PackageVersion Include="Namh.Configuration.Template" Version="1.0.1" />
<PackageReference Include="Namh.Configuration.Template" />
paket add Namh.Configuration.Template --version 1.0.1
#r "nuget: Namh.Configuration.Template, 1.0.1"
#:package Namh.Configuration.Template@1.0.1
#addin nuget:?package=Namh.Configuration.Template&version=1.0.1
#tool nuget:?package=Namh.Configuration.Template&version=1.0.1
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.1
using Microsoft.Extensions.Configuration;
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.BuildTemplateConfig();
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.1 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" ]
}
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/Template.slnx
dotnet test src/Template.slnx
| 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.