Routya.ConfigKit.Generator 1.0.1

dotnet add package Routya.ConfigKit.Generator --version 1.0.1
                    
NuGet\Install-Package Routya.ConfigKit.Generator -Version 1.0.1
                    
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="Routya.ConfigKit.Generator" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Routya.ConfigKit.Generator" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Routya.ConfigKit.Generator" />
                    
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 Routya.ConfigKit.Generator --version 1.0.1
                    
#r "nuget: Routya.ConfigKit.Generator, 1.0.1"
                    
#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 Routya.ConfigKit.Generator@1.0.1
                    
#: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=Routya.ConfigKit.Generator&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Routya.ConfigKit.Generator&version=1.0.1
                    
Install as a Cake Tool

⚙️ Routya.ConfigKit.Generator

🔧 A lightweight, source-generated configuration binder for .NET — just tag your class with [ConfigSection] and go.

CI CI NuGet NuGet


✨ Features

  • ✅ Compile-time generation of config binding and registration code
  • ✅ Supports both IOptions<T> and AddSingleton<T> modes
  • ✅ Full support for System.ComponentModel.Annotations
  • ✅ No reflection at runtime
  • ✅ Drop-in integration with appsettings.json
  • ✅ Currently only supports {get; set;} and {get; init;}.

🚀 Getting Started

🛠 Binding Modes | Mode | Behavior | |-------------|----------------------------------------| | Singleton | Registers the instance via AddSingleton<T> | | IOptions | Uses services.Configure<T>() | | Both | Adds both for flexibility |

1. Install package

dotnet add package Routya.ConfigKit.Generator

2. Create your config class

ConfigSection("MyService", ConfigBindingMode.IOptions)

The 'MyService' in ConfigSection is the section name within your configuration (eg. appsettings.json, Azure App Configuration)

{
  "MyService": {
    "RetryCount": 3,
    "UseCaching": false
  }
}

ConfigBindingMode.IOptions

using System.ComponentModel.DataAnnotations;
using Routya.ConfigKit;

[ConfigSection("MyService", mode: ConfigBindingMode.IOptions)]
public partial class MyServiceOptions
{
    [Required]
    public int RetryCount { get; init; }

    public bool UseCaching { get; init; } = true;
}

Generates

public static IServiceCollection AddMyServiceOptions(this IServiceCollection services, IConfiguration configuration)
{
	services.AddOptions<MyServiceOptions>()
			.Bind(configuration.GetSection("MyService"))
			.ValidateDataAnnotations()
			.ValidateOnStart();

	return services;
}

ConfigBindingMode.Singleton

using System.ComponentModel.DataAnnotations;
using Routya.ConfigKit;

[ConfigSection("MyService", ConfigBindingMode.Singleton)]
public partial class MyServiceOptions
{
    [Required]
    public int RetryCount { get; init; }

    public bool UseCaching { get; init; } = true;
}

Generates

 public static IServiceCollection AddMyServiceOptions(this IServiceCollection services, IConfiguration configuration)
 {
     var options = new MyServiceOptions()
     {
         RetryCount = configuration.GetValue<int>("MyService:RetryCount"),
         UseCaching = configuration.GetValue<bool>("MyService:UseCaching"),
     };

     var validationContext = new ValidationContext(options);
     Validator.ValidateObject(options, validationContext, validateAllProperties: true);

     services.AddSingleton(options);

     return services;
 }

3. Register the generated method in your startup

builder.Services.AddMyServiceOptions(builder.Configuration);

📅 Roadmap

  • Add support for complex/nested config objects
  • {get; private set;}

🔍 More from this author

🧰 Routya

A high-performance, minimal-overhead CQRS + MediatR alternative for .NET applications. Supports request/notification dispatching, behavior pipelines, scoped resolution, and performance-optimized dispatchers.

📦 Routya.ResultKit

A companion library for consistent API response modeling. Wraps results with success/failure metadata, integrates with ProblemDetails, and streamlines controller return types.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

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.0.1 171 5/1/2025
1.0.0 331 5/1/2025 1.0.0 is deprecated because it is no longer maintained.