Neovolve.Configuration.DependencyInjection 1.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Neovolve.Configuration.DependencyInjection --version 1.1.0                
NuGet\Install-Package Neovolve.Configuration.DependencyInjection -Version 1.1.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="Neovolve.Configuration.DependencyInjection" Version="1.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Neovolve.Configuration.DependencyInjection --version 1.1.0                
#r "nuget: Neovolve.Configuration.DependencyInjection, 1.1.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.
// Install Neovolve.Configuration.DependencyInjection as a Cake Addin
#addin nuget:?package=Neovolve.Configuration.DependencyInjection&version=1.1.0

// Install Neovolve.Configuration.DependencyInjection as a Cake Tool
#tool nuget:?package=Neovolve.Configuration.DependencyInjection&version=1.1.0                

Introduction

The Neovolve.Configuration.DependencyInjection NuGet package provides IHostBuilder extension methods for adding dependency injection support for nested configuration types with hot reload support.

GitHub license   Nuget   Nuget

Actions Status

Installation

The package can be installed from NuGet using Install-Package Neovolve.Configuration.DependencyInjection.

Usage

Limitations

This extension uses type information to recurse through all the available properties and their types defined against the root configuration type. If any of the property types are defined as interfaces then the extension will register configuration types according to those interface definitions rather than any concrete type that the property may hold at runtime. This reason for this is that the extesion does not bind the configuration objects to recurse through the runtime configuration data but instead relies purely on the type information.

For example consider the following type structure:


public interface IConfig
{
    string RootValue { get; }
}

public class Config : IConfig
{
    public IFirstConfig First { get; } = new FirstConfig();

    public string RootValue { get; set; }
}

public interface IFirstConfig
{
    string FirstValue { get; }
}

public class FirstConfig : IFirstConfig
{
    public string FirstValue { get; set; }

    public SecondConfig Second { get; } = new();
}

public interface ISecondConfig
{
    string SecondValue { get; }
}

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Host.ConfigureWith<Config>();

Using this extension on Config would result in the following service registrations:

Config
IConfig
IOptions<Config>
IOptions<IConfig>
ISnapshotOptions<Config>
ISnapshotOptions<IConfig>
IMonitorOptions<Config>
IMonitorOptions<IConfig>
IOptions<FirstConfig>
IOptions<IFirstConfig>
ISnapshotOptions<FirstConfig>
ISnapshotOptions<IFirstConfig>
MonitorOptions<FirstConfig>
IMonitorOptions<IFirstConfig>

There would be no registrations for the following types:

IOptions<SecondConfig>
IOptions<ISecondConfig>
ISnapshotOptions<SecondConfig>
ISnapshotOptions<ISecondConfig>
MonitorOptions<SecondConfig>
IMonitorOptions<ISecondConfig>

You will need to define the properties on configuration types that provides the greatest reach of type information possible. The additional types above would be registered if the config class defined the First property type as FirstConfig rather than IFirstConfig.

public class Config : IConfig
{
    public FirstConfig First { get; } = new FirstConfig();

    public string RootValue { get; set; }
}

When Config.First is FirstConfig rather than IFirstConfig then the type searching logic can find the Second property on FirstConfig which is not defined on the interface.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in 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.4.0 223 8/4/2024
1.3.2-beta0001 88 6/9/2024
1.3.1 127 5/23/2024
1.3.1-beta0001 103 5/23/2024
1.3.0 112 5/23/2024
1.3.0-beta0002 86 5/23/2024
1.2.1-beta0001 94 5/23/2024
1.2.0 166 4/13/2024
1.2.0-beta0002 107 4/13/2024
1.2.0-beta0001 100 4/13/2024
1.1.0 145 9/28/2023
1.0.1-beta0001 104 9/28/2023
0.1.0-beta0006 113 9/26/2023
0.1.0-beta0003 130 8/30/2023
0.1.0-beta0001 138 8/30/2023