SourceCrafter.DependencyInjection.MsConfiguration 2.26.286.181

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

SourceCrafter.DependencyInjection.MsConfiguration

Purpose

Code generator with Microsoft.Extensions.Configuration support. This package extends the core SourceCrafter.DependencyInjection generator to add compile-time support for strongly-typed configuration loading from appsettings.json and other IConfiguration sources.

What It Provides

This is the Roslyn code generator that processes your container and generates optimized resolvers with full Microsoft.Extensions.Configuration integration:

  • Analyzes [ServiceProvider] classes and service attributes
  • Generates configuration-aware resolver methods
  • Supports [JsonSetting<T>] for strongly-typed settings
  • Integrates with IConfiguration from Microsoft.Extensions.DependencyInjection
  • Generates async-aware, cached resolution code

Installation

dotnet add package SourceCrafter.DependencyInjection
dotnet add package SourceCrafter.DependencyInjection.Metadata
dotnet add package SourceCrafter.DependencyInjection.MsConfiguration
dotnet add package SourceCrafter.DependencyInjection.MsConfiguration.Metadata

This includes support for:

  • [JsonSetting<T>(section)] – Load settings from JSON configuration
  • Seamless IConfiguration integration
  • Dynamic configuration reloading
  • Configuration validation at compile time

Core Package Only (No Configuration)

If you don't need Microsoft.Extensions.Configuration:

dotnet add package SourceCrafter.DependencyInjection

Microsoft.Extensions.Configuration Support

Loading Typed Settings

Decorate your container with [JsonSetting<T>] to load configuration:

[assembly: JsonConfiguration]

[ServiceProvider]
[JsonSetting<AppSettings>("AppSettings")]
[Singleton<IDatabase, Database>]
public partial class ServiceContainer;

public class AppSettings {
    public string ConnectionString { get; set; }
    public int Timeout { get; set; }
}

The generator creates:


public partial class ServiceContainer
{
    private static global::Microsoft.Extensions.Configuration.IConfiguration? _configuration = null;

    internal global::Microsoft.Extensions.Configuration.IConfiguration Configuration
    {
        get
        {
            if(_configuration is not null) return _configuration;

            lock (this)
            {
                var fileName = global::System.IO.Path.GetFullPath("appsettings");

                return _configuration ??= new global::Microsoft.Extensions.Configuration.ConfigurationBuilder()
                    .AddJsonFile($"{fileName}.{EnvironmentName}.json", true, true)
                    .AddJsonFile($"{fileName}.json", true, true)
                    .Build();
            }
        }
    }

    private static global::SourceCrafter.DependencyInjection.Tests.AppSettings? _appSettings = default;

    internal global::SourceCrafter.DependencyInjection.Tests.AppSettings Settings
    {
        get
        {
            if (_appSettings is not null) return _appSettings;
            
            lock (this)     

            return _appSettings ??= BuildSetting();

            global::SourceCrafter.DependencyInjection.Tests.AppSettings BuildSetting()
            {
                global::SourceCrafter.DependencyInjection.Tests.AppSettings setting = new global::SourceCrafter.DependencyInjection.Tests.AppSettings();

                Configuration
                    .GetSection("AppSettings")                
                    .Bind(setting);

                return setting;
            }
        }
    }

}

At Runtime

// With IConfiguration from appsettings.json
var container = new ServiceContainer();
var settings = await container.Settings;
var database = await container.GetDatabaseAsync();  // Probably uses settings

Configuration Reloading

Configuration changes are detected automatically:

  • Singleton settings load once and cache
  • Scoped settings respect configuration changes per scope
  • No manual refresh needed

Code Generation

At Compile Time

  1. Scans your container class decorated with [ServiceProvider]
  2. Analyzes all registered services: [Singleton], [Scoped], [Transient], [JsonSetting<T>]
  3. Builds dependency graph and validates configuration section mapping
  4. Generates resolver methods with configuration binding and caching logic
  5. Creates disposal routines for IDisposable/IAsyncDisposable services
  6. Produces Scoped inner class for per-instance service and configuration isolation

Key Features

  • Compile-Time Safety: Type-checked service resolution + configuration schema validation
  • Zero Runtime Reflection: No dictionaries, no dynamic instantiation, no Activator.CreateInstance
  • Configuration Binding: Strongly-typed [JsonSetting<T>] with compile-time validation
  • Smart Async: Caches Task<T> and ValueTask<T> results; prevents redundant execution
  • Intelligent Disposal: Detects and applies IDisposable or IAsyncDisposable automatically
  • Scoped Isolation: Per-instance configuration and service caching for request-local state
  • Configuration Hot-Reload: Respects configuration changes in scoped contexts

Use MsConfiguration when you need to load settings from appsettings.json or IConfiguration
Use Core package when you only need service registration without configuration


References

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • net10.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.

Version Downloads Last Updated
2.26.286.181 86 10/13/2026
2.26.283.228 88 10/10/2026
2.26.282.289 80 10/9/2026
2.26.282.142 85 10/9/2026
2.26.273.86 97 9/30/2026
2.26.265.50 98 9/22/2026
2.26.263.311 108 9/20/2026
2.26.262.371 100 9/19/2026
2.26.262.287 102 9/19/2026
2.26.262.202 98 9/19/2026
2.26.261.445 97 9/18/2026
2.26.249.144 148 9/6/2026
2.26.233.161 109 8/21/2026
2.26.227.290 112 8/15/2026
2.26.226.430 110 8/14/2026
2.26.226.81 113 8/14/2026
2.26.212.228 122 7/31/2026
2.26.212.105 117 7/31/2026
2.26.211.464 117 7/30/2026
2.26.206.340 118 7/25/2026
Loading failed