Conphig 0.9.3
See the version list below for details.
dotnet add package Conphig --version 0.9.3
NuGet\Install-Package Conphig -Version 0.9.3
<PackageReference Include="Conphig" Version="0.9.3" />
paket add Conphig --version 0.9.3
#r "nuget: Conphig, 0.9.3"
// Install Conphig as a Cake Addin
#addin nuget:?package=Conphig&version=0.9.3
// Install Conphig as a Cake Tool
#tool nuget:?package=Conphig&version=0.9.3
conphig
Conphig is a .NET 5 package for loading configuration from JSON files, command line and environment variables.
Getting started
After installing the Conphig
package, create a simple POCO class and place your configuration items as properties inside.
For each property, use the JsonPropertyName
, CommandLine
, EnvironmentVariable
, and Default
attributes to control how that property is deserialized from JSON files, command line parameters and environment variables, and what the default value is.
Then, in your Main
method (or somewhere else that makes sense given your app startup code), add a call to Config.Load<T>
to create and populate an object containing your configuration items.
Example configuration class
using System.Text.Json.Serialization;
using ATornblad.Conphig;
namespace MyApp
{
[Filename("app-configuration.json")]
public class Settings
{
[Default("Untitled")]
[JsonPropertyName("title")]
[EnvironmentVariable("TITLE")]
[CommandLine("-t", "--title")]
public string Title { get; set; }
[JsonPropertyName("Categories")]
[CommandLine("-c", "--category")]
public string[] Categories { get; set; }
[EnvironmentVariable("API_KEY")]
public string ApiKey { get; set; }
}
}
Example of loading
using System;
using ATornblad.Conphig;
namespace MyApp
{
public class Program
{
public static void Main(string[] args)
{
var settings = Config.Load<Settings>();
Console.WriteLine($"Title: {settings.Title}");
}
}
}
Example of configuration file
{
"title": "Title from JSON file",
"categories": [
"API",
"Programming",
"C#"
]
}
Example of command line arguments
myapp -t "Title from Command Line" -c API -c Programming -c bash
Read more
For more information, visit the Project Website
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. 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 was computed. 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. |
-
net5.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
v0.9.0 : First release
v0.9.1 : Added support for array properties
v0.9.2 : Added better package documentation