Mastersign.ConfigModel 1.2.0

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

// Install Mastersign.ConfigModel as a Cake Tool
#tool nuget:?package=Mastersign.ConfigModel&version=1.2.0                

Mastersign.ConfigModel

YAML based configuration model for .NET applications

NuGet Package

This library is designed for the following use case: You have an application needing a rather large configuration. And you typically write the configuration by hand or modify only parts of it with scripts, or by the application itself. To keep the configuration lucid, you like to spread it over multiple easy to manage files in a fitting directory structure. You like to automatically reload the configuration, when one file of the configuration changes.

What this library not supports is a full round-trip for a configuration. Where you load it from file(s), modify it during the runtime of the application and write it back to disk.

Features

  • Includes
  • String sourcing from text files
  • Multiple layers
  • Optional merge or replace for items in dictionaries / lists
  • Auto reload on file change

See Project Website for more details.

Example

This example demonstrates a small configuration model with two classes: ProjectModel and DataModel.

The ProjectModel has three public readable and writable properties. One has the type DataModel as example for a nested data structure. The DataModel class has a property with a dictionary with string keys as an example for a generic map structure.

[MergableConfigModel]
class ProjectModel : ConfigModelBase
{
    public string? ProjectName { get; set; }

    public string? Description { get; set; }

    public DataModel? Data { get; set; }
}

[MergableConfigModel]
class DataModel : ConfigModelBase
{
    public int? Version { get; set; }

    public Dictionary<string, int> Values { get; set; }
}

The following code demonstrates creating a manager for the configuration model, loading the model, and watching for changes for automatic reload.

The model is loaded by adding the two layers config\1-defaults.yaml, and config\2-main.yaml with a globbing pattern *.yaml in the root folder config.

using Mastersign.ConfigModel;
using System.IO;

static class Program
{
    static string ConfigurationFolder => Path.Combine(Environment.CurrentDirectory, "config");

    static ConfigModelManager modelManager;

    static ProjectModel Model { get; set; }

    static void HandleModelReload(object sender, ConfigModelReloadEventArgs ea)
    {
        Model = ea.NewModel;
        Console.WriteLine("Model reloaded.");
    }

    static void Main()
    {
        modelManager = new ConfigModelManager<ProjectModel>();

        manager.AddLayers("*.yaml", ConfigurationFolder);
        Model = manager.LoadModel();

        manager.ModelReload += HandleModelReload;
        manager.WatchAndReload();

        // your application logic here
    }
}

You could use the following configuration files. The directory structure is arbitrary, and chosen for this example to demonstrate various features of the library. Feel free to design your own directory structure for your configuration.

  • config
    • includes
      • data.yaml
      • user.inc.yaml
    • strings
      • description.txt
    • 1-defaults.yaml
    • 2-main.yaml

config\1-defaults.yaml:

Project: Unnamed
Description: No Description
Child:
  Version: 1

config\2-main.yaml:

$includes:
  - includes/*.inc.yaml

Data:
  $includes:
    - includes\data.yaml

config\includes\user.inc.yaml:

Project: My Project

$sources:
  Description: ../strings/description.txt

config\includes\data.yaml:

Values:
  x: 100
  y: 200

config\strings\description.txt:

A long project description
with multiple lines and more text,
then you would like to have in your YAML files.

The loaded model would contain the following data:

Project: My Project
Description: A long project description...
Data:
  Version: 1
  Values:
    x: 100
    y: 200

License

This project is licensed under the MIT license.
Copyright by Tobias Kiertscher dev@mastersign.de.

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.5.0 349 5/16/2023
1.4.0 167 5/8/2023
1.3.0 141 5/5/2023
1.2.0 154 5/3/2023
1.1.3 149 5/2/2023
1.1.2 176 4/28/2023
1.1.1 159 4/28/2023
1.1.0 164 4/27/2023
1.0.0 169 4/26/2023