aemarcoToolboxAppOptions 2.0.2

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

// Install aemarcoToolboxAppOptions as a Cake Tool
#tool nuget:?package=aemarcoToolboxAppOptions&version=2.0.2

aemarcoToolboxAppOptions

<a href=https://www.nuget.org/packages/aemarcoToolboxAppOptions><img src="https://buildstats.info/nuget/aemarcoToolboxAppOptions"></a><br/>

Overview

This package provides a opinionated approach to the Options pattern described in the Microsoft docs. With minimal setup, all the Option classes will be registered in the IOC container and mapped to the IConfiguration source.

  • Automatic mapping of sections to classes (convention driven, but can be adjusted)
  • Beside registering the interfaces from Microsoft, registers the class itself as well (singleton)
  • Registers also interfaces which you put on the settings class
  • Allows text transformations between IConfiguration and the settings class
  • Option to use fluent validation on settings
  • Option to validate settings during startup (on by default, opt-out in options)

Get Started

During startup of the app

{
  services.AddConfigOptionsUtils(config);
}

Create your class representing your options

{
  public class MySettings : SettingsBase
  {
    public string? Text { get; set; }
    public bool Enable { get; set; }
  }
}

In appsetting.json (or other IConfiguration source)

{
    "MySettings": {
        
        "Text": "SomeText",
        "Enable": true
    }
}

StringTransformation

String transformations will be executed in the order defined in the setup process. You could define your own, but PlaceholderTransformation is built in already.

{
    services.AddConfigOptionsUtils(
        config,
        x => x
            .AddStringTransformation(new PlaceholderTransformation());
}

PlaceholderTransformation does resolve placeholders {{{...}}} through the entire IConfguration by Key. That maybe usefull when piecing together file or url path.

{
    "Message": "Hello world!",
    "MySettings": {
        
        "Text": "The message is {{{Message}}}",
        "Enable": true
    }
}

Fluent Validation

Just define your Validators in the assemblies where setting classes are defined. The tool will register them, and use them if present. By default, Validation takes place at startup.

{
    services.AddConfigOptionsUtils(
        config,
        x => x
            .EnableValidationOnStartup(false); //on by default
}

Setting classes in multiple assemblies

The tool relies on assembly scanning during the setup. If your option classes are in other assemblies, you may pass one of the types as assembly marker, and/or use the assemblies itself.

{
    services.AddConfigOptionsUtils(
        config,
        x => x
            .AddAssemblyMarker(typeof(MySettings))
            // and/or
            .AddAssemblyMarker(someAssemblyArray));
}

Mapping Path

By default, the class name is exactly matched to the root level of the configuration. You may define your own path in the settings class

{
  [SettingsPath("Settings")]
  public class MySettings : SettingsBase
  {
    public string? Text { get; set; }
    public bool Enable { get; set; }
  }
}

would map to

{
    "Settings": {
        
        "Text": "SomeText",
        "Enable": true
    }
}

You could even do it nested, just use the colon seperated path as you would with GetSection().

{
  [SettingsPath("Settings:Nested")]
  public class MySettings : SettingsBase
  {
    public string? Text { get; set; }
    public bool Enable { get; set; }
  }
}

would map to

{
    "Settings": {
        "Nested":{
            "Text": "SomeText",
            "Enable": true
        }
    }
}
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 (3)

Showing the top 3 NuGet packages that depend on aemarcoToolboxAppOptions:

Package Downloads
aemarcoWpfTools

c# wpf tools collection

aemarcoWebTools

c# web tools collection

aemarcoConsoleTools

c# console tools collection

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.1.17 82 4/12/2024
3.1.16 87 4/4/2024
3.1.15 102 3/22/2024
3.1.11 87 3/19/2024
3.1.10 83 2/16/2024
3.1.7 107 2/11/2024
3.1.6 91 2/11/2024
3.1.5 85 2/11/2024
3.1.4 85 2/11/2024
3.0.18 113 1/29/2024
3.0.17 73 1/29/2024
3.0.16 75 1/27/2024
3.0.15 74 1/27/2024
3.0.8 69 1/27/2024
3.0.7 132 1/13/2024
2.0.18 137 1/4/2024
2.0.17 149 1/1/2024
2.0.16 146 12/27/2023
2.0.15 135 12/26/2023
2.0.14 136 12/26/2023
2.0.13 117 12/25/2023
2.0.11 96 12/23/2023
2.0.10 141 12/16/2023
2.0.9 122 12/15/2023
2.0.8 134 12/14/2023
2.0.7 118 12/13/2023
2.0.5 143 12/11/2023
2.0.4 137 12/11/2023
2.0.2 143 12/10/2023
1.9.2 109 12/10/2023
1.8.4 154 12/10/2023
1.8.3 155 12/9/2023
1.8.2 145 12/9/2023
1.1.28 179 11/27/2023
1.1.27 136 11/26/2023
1.1.26 161 11/18/2023
1.1.25 121 11/17/2023
1.1.24 191 10/30/2023
1.1.23 166 10/29/2023
1.1.22 165 10/22/2023
1.1.21 177 10/17/2023
1.1.20 185 9/16/2023
1.1.19 248 8/27/2023
1.1.18 184 7/31/2023
1.1.17 221 7/16/2023
1.1.16 211 7/9/2023
1.1.15 233 7/8/2023
1.1.14 240 7/5/2023
1.1.13 220 6/29/2023
1.1.12 219 5/1/2023
1.1.11 403 3/5/2023
1.1.10 364 3/3/2023
1.1.9 370 2/28/2023
1.1.7 387 2/26/2023
1.1.6 377 2/26/2023
1.1.5 256 2/26/2023
1.1.3 246 2/25/2023