Kiwify.Kiwi.Configuration 1.0.0

Prefix Reserved
dotnet add package Kiwify.Kiwi.Configuration --version 1.0.0
                    
NuGet\Install-Package Kiwify.Kiwi.Configuration -Version 1.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="Kiwify.Kiwi.Configuration" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Kiwify.Kiwi.Configuration" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Kiwify.Kiwi.Configuration" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Kiwify.Kiwi.Configuration --version 1.0.0
                    
#r "nuget: Kiwify.Kiwi.Configuration, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Kiwify.Kiwi.Configuration@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Kiwify.Kiwi.Configuration&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Kiwify.Kiwi.Configuration&version=1.0.0
                    
Install as a Cake Tool

Kiwi Config

Attribute-driven configuration binding for .NET. Declare what your configuration looks like - in code, next to the code that uses it - and let the library do the binding.

Key principle: configuration errors should fail at startup, not at runtime.


The Problem with Standard .NET Configuration

// IConfiguration: stringly-typed, silent failures
var port = int.Parse(config["app:port"] ?? "5000");
var name = config["app:name"] ?? "MyApp";

// ConfigurationBinder.Bind(): implicit, no declared intent
var settings = new AppSettings();
configuration.GetSection("app").Bind(settings);
// Which keys does AppSettings read? What are its defaults? Open the class to find out.

A typo in a key compiles fine. A missing required value surfaces as a NullReferenceException at runtime. Defaults are scattered across the codebase.


The Kiwi Config Approach

The config class is the schema. Every key it reads, every default it applies, and every field it requires is declared directly on the class as an attribute.

using Kiwify.Kiwi.Platform.Configuration.Attributes;

[ConfigSection("app")]
public class AppConfig
{
    [ConfigKey("name", "MyApp")]
    public string Name { get; private set; } = string.Empty;

    [ConfigKey("port", 5000)]
    public int Port { get; private set; }

    [ConfigKey("connection-string", Required = true)]
    public string ConnectionString { get; private set; } = string.Empty;
}

One glance at the class tells you everything: which section it lives in, which keys it reads, what the defaults are, and which fields are mandatory. No separate documentation required.


Installation

<PackageReference Include="Kiwify.Kiwi.Configuration" Version="1.0.0" />

Microsoft.Extensions.Configuration is included transitively. No other dependencies.


Quick Start

using Kiwify.Kiwi.Platform.Configuration;
using Kiwify.Kiwi.Platform.Configuration.Attributes;
using Microsoft.Extensions.Configuration;

var configuration = new ConfigurationBuilder()
    .AddJsonFile("appsettings.json")
    .AddEnvironmentVariables()   // env vars override file values
    .Build();

var appConfig = configuration.LoadConfiguration<AppConfig>();

Console.WriteLine($"Starting {appConfig.Name} on port {appConfig.Port}");
// Output: Starting ProductionApp on port 8080

appsettings.json:

{
  "app": {
    "name": "ProductionApp",
    "port": 8080,
    "connection-string": "Server=db.example.com;Database=prod"
  }
}

LoadConfiguration<T> is an extension method on IConfiguration. No DI container is required - it works in CLI tools, test fixtures, and anywhere you have an IConfiguration.

If a required key is missing or a value cannot be converted to the declared type, it throws immediately with a clear message identifying exactly which key failed - at startup, not at runtime.


Nested Configuration

Compose config classes the same way the JSON they come from is composed:

[ConfigSection("app")]
public class AppConfig
{
    [ConfigKey("name", "MyApp")]
    public string Name { get; private set; } = string.Empty;

    [ConfigObject]                       // resolved at "app:database:..."
    public DatabaseConfig Database { get; private set; } = null!;
}

[ConfigSection("database")]
public class DatabaseConfig
{
    [ConfigKey("server", "localhost")]
    public string Server { get; private set; } = string.Empty;

    [ConfigKey("port", 5432)]
    public int Port { get; private set; }
}
{
  "app": {
    "name": "MyApp",
    "database": { "server": "db.example.com", "port": 5432 }
  }
}

Dynamic Defaults

For defaults that cannot be a compile-time constant - environment variables, machine characteristics, generated values - define a static method named GetDefault{PropertyName}:

[ConfigSection("app")]
public class AppConfig
{
    [ConfigKey("instance-id")]
    public string InstanceId { get; private set; } = string.Empty;

    public static string GetDefaultInstanceId() => Environment.MachineName;
}

The method is called only when the key is absent from configuration.


Feature Summary

Feature IConfiguration Bind() / IOptions<T> Kiwi Config
Strongly-typed binding -
Explicit key declarations - -
Per-property defaults - -
Required-field validation - -
Dynamic defaults (GetDefault*) - -
Works without DI container -
Private setter support - -
Hierarchical nesting with type safety -

Type support: string, int, long, double, decimal, bool, DateTime, TimeSpan, Guid, any enum, and string[] / List<string> collections.


Using with Kiwi DI

If you also use Kiwify.Kiwi.DependencyInjection, add [ConfigService] to have your config class auto-loaded and registered as a DI singleton in a single AddKiwiServices() call.

[ConfigSection("app")]
[ConfigService]           // auto-loaded and injected anywhere in the container
public class AppConfig { ... }

Kiwify.Kiwi.Configuration is included transitively by Kiwify.Kiwi.DependencyInjection.


Part of Kiwi Foundation

Kiwi Config is one library in Kiwi Foundation, a suite of .NET frameworks built around a single idea: developers should focus on business logic, not infrastructure boilerplate.

Product 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.  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.  net10.0 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Kiwify.Kiwi.Configuration:

Package Downloads
Kiwify.Kiwi.DependencyInjection

Attribute-driven dependency injection for .NET. Replace scattered AddScoped/AddSingleton startup code with attributes that live next to the classes they describe - registration, conditional activation, and config-driven wiring in a single AddKiwiServices call.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 123 5/6/2026