Davasorus.Utility.DotNet.Config 2026.2.1.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package Davasorus.Utility.DotNet.Config --version 2026.2.1.2
                    
NuGet\Install-Package Davasorus.Utility.DotNet.Config -Version 2026.2.1.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="Davasorus.Utility.DotNet.Config" Version="2026.2.1.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Davasorus.Utility.DotNet.Config" Version="2026.2.1.2" />
                    
Directory.Packages.props
<PackageReference Include="Davasorus.Utility.DotNet.Config" />
                    
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 Davasorus.Utility.DotNet.Config --version 2026.2.1.2
                    
#r "nuget: Davasorus.Utility.DotNet.Config, 2026.2.1.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.
#:package Davasorus.Utility.DotNet.Config@2026.2.1.2
                    
#: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=Davasorus.Utility.DotNet.Config&version=2026.2.1.2
                    
Install as a Cake Addin
#tool nuget:?package=Davasorus.Utility.DotNet.Config&version=2026.2.1.2
                    
Install as a Cake Tool

Davasorus.Utility.DotNet.Config

Davasorus.Utility.DotNet.Config provides utilities for loading, creating, converting, and updating configuration files (JSON, XML, and YAML) in .NET 8+ applications. It is designed for use with dependency injection (DI) and follows a strict service/client separation: end users should only interact with the Service interfaces; the Service classes handle all client interactions, error handling, and logging.

Features

  • Load, create, convert, and update configuration files in JSON, XML, and YAML formats
  • Full CRUD operations for each format (Load, Create, Convert, Update)
  • Robust error handling and logging (SQS integration)
  • Designed for DI: Service = Scoped, Client = Transient

Dependency Injection Setup

Use the fluent configuration API to register services easily:

using Tyler.Utility.DotNet.Config.Configuration;

// Register only JSON services (Load, Create, Convert, Update)
services.AddConfigServices(config => config.AddJsonServices());

// Register only XML services (Load, Create, Convert, Update)
services.AddConfigServices(config => config.AddXmlServices());

// Register only YAML services (Load, Create, Convert, Update)
services.AddConfigServices(config => config.AddYamlServices());

// Register all services (JSON + XML + YAML)
services.AddConfigServices(config => config.AddAllServices());

// Or chain them explicitly
services.AddConfigServices(config => config
    .AddJsonServices()
    .AddXmlServices()
    .AddYamlServices());

Alternative: Individual Service Registration

You can also register services individually if you need fine-grained control:

// JSON services
services.AddJsonConfigServices();

// XML services
services.AddXmlConfigServices();

// YAML services
services.AddYamlConfigServices();

// All services
services.AddAllConfigServices();

Manual Registration (Legacy)

If you prefer manual registration:

// JSON
services.AddScoped<ILoadJSONService, LoadJSONService>();
services.AddTransient<ILoadJSONClient, LoadJSONClient>();
services.AddScoped<ICreateJSONService, CreateJSONService>();
services.AddTransient<ICreateJSONClient, CreateJSONClient>();
services.AddScoped<IConvertToJSONService, ConvertToJSONService>();
services.AddTransient<IConvertToJSONClient, ConvertToJSONClient>();
services.AddScoped<IUpdateJSONService, UpdateJSONService>();
services.AddTransient<IUpdateJSONClient, UpdateJSONClient>();

// XML
services.AddScoped<ILoadXmlService, LoadXmlService>();
services.AddTransient<ILoadXMLClient, LoadXMLClient>();
services.AddScoped<ICreateXMLService, CreateXMLService>();
services.AddTransient<ICreateXMLClient, CreateXMLClient>();
services.AddScoped<IConvertToXMLService, ConvertToXMLService>();
services.AddTransient<IConvertToXMLClient, ConvertToXMLClient>();
services.AddScoped<IUpdateXMLService, UpdateXMLService>();
services.AddTransient<IUpdateXMLClient, UpdateXMLClient>();

// YAML
services.AddScoped<ILoadYAMLService, LoadYAMLService>();
services.AddTransient<ILoadYAMLClient, LoadYAMLClient>();
services.AddScoped<ICreateYAMLService, CreateYAMLService>();
services.AddTransient<ICreateYAMLClient, CreateYAMLClient>();
services.AddScoped<IConvertToYAMLService, ConvertToYAMLService>();
services.AddTransient<IConvertToYAMLClient, ConvertToYAMLClient>();
services.AddScoped<IUpdateYAMLService, UpdateYAMLService>();
services.AddTransient<IUpdateYAMLClient, UpdateYAMLClient>();

Note: Only use the Service interfaces (ILoadJSONService, ICreateJSONService, ILoadXmlService, ILoadYAMLService, etc.) in your application code. The Service classes manage all communication with their respective Client classes internally.

Example Usage

Load JSON File

public class MyConfigLoader
{
    private readonly ILoadJSONService _loadJsonService;
    public MyConfigLoader(ILoadJSONService loadJsonService)
    {
        _loadJsonService = loadJsonService;
    }

    public async Task<MyConfigModel?> LoadConfigAsync(string path, string fileName)
    {
        return await _loadJsonService.LoadDataFromJsonFile<MyConfigModel>(path, fileName);
    }
}

Create JSON File

public class MyConfigCreator
{
    private readonly ICreateJSONService _createJsonService;
    public MyConfigCreator(ICreateJSONService createJsonService)
    {
        _createJsonService = createJsonService;
    }

    public async Task CreateConfigAsync(string path, string fileName, MyConfigModel config)
    {
        await _createJsonService.CreateJsonFileAsync(path, fileName, config);
    }
}

Convert File or Text to JSON

public class MyConverter
{
    private readonly IConvertToJSONService _convertToJsonService;
    public MyConverter(IConvertToJSONService convertToJsonService)
    {
        _convertToJsonService = convertToJsonService;
    }

    public async Task<string?> ConvertFileAsync(string filePath)
    {
        return await _convertToJsonService.ConvertFileToJsonAsync(filePath);
    }

    public async Task<string?> ConvertTextAsync(string text)
    {
        return await _convertToJsonService.ConvertTextToJsonInMemoryAsync(text);
    }
}

Update JSON File (Merge, Overwrite, or Add)

public class MyConfigUpdater
{
    private readonly IUpdateJSONService _updateJsonService;
    public MyConfigUpdater(IUpdateJSONService updateJsonService)
    {
        _updateJsonService = updateJsonService;
    }

    // Merge new data into existing JSON file
    public async Task UpdateConfigAsync(string path, string fileName, MyConfigModel newData)
    {
        await _updateJsonService.UpdateJsonFileAsync(path, fileName, newData);
    }

    // Overwrite JSON file with new data
    public async Task OverwriteConfigAsync(string path, string fileName, MyConfigModel newData)
    {
        await _updateJsonService.OverwriteJsonFileAsync(path, fileName, newData);
    }

    // Add new data to JSON file (adds new keys only)
    public async Task AddToConfigAsync(string path, string fileName, MyConfigModel newData)
    {
        await _updateJsonService.AddToJSONFileAsync(path, fileName, newData);
    }
}

Load XML File

public class MyXmlLoader
{
    private readonly ILoadXmlService _loadXmlService;
    public MyXmlLoader(ILoadXmlService loadXmlService)
    {
        _loadXmlService = loadXmlService;
    }

    // Load and deserialize an XML file
    public async Task<MyConfigModel?> LoadConfigAsync(string path, string fileName)
    {
        return await _loadXmlService.LoadDataFromXmlFile<MyConfigModel>(path, fileName);
    }

    // Load descendants matching an attribute and value
    public async Task<List<XElement>?> LoadDescendantsAsync(string path, string parent, string searchAttribute, string searchValue)
    {
        return await _loadXmlService.LoadDescendants(path, parent, searchAttribute, searchValue);
    }

    // Load attributes matching an attribute name
    public async Task<List<XAttribute>?> LoadElementsAsync(string path, string parent, string searchAttribute)
    {
        return await _loadXmlService.LoadElements(path, parent, searchAttribute);
    }
}

Create, Convert, and Update XML Files

// Create XML file
await _createXmlService.CreateXmlFileAsync(path, fileName, config);

// Convert file to XML
string? xmlPath = await _convertToXmlService.ConvertFileToXmlAsync(filePath);

// Convert text to XML in memory
string? xml = await _convertToXmlService.ConvertTextToXmlInMemoryAsync(text);

// Update (merge), overwrite, or add to XML file
await _updateXmlService.UpdateXmlFileAsync(path, fileName, data);
await _updateXmlService.OverwriteXmlFileAsync(path, fileName, data);
await _updateXmlService.AddToXmlFileAsync(path, fileName, data);

Load YAML File

public class MyYamlLoader
{
    private readonly ILoadYAMLService _loadYamlService;
    public MyYamlLoader(ILoadYAMLService loadYamlService)
    {
        _loadYamlService = loadYamlService;
    }

    public async Task<MyConfigModel?> LoadConfigAsync(string path, string fileName)
    {
        return await _loadYamlService.LoadDataFromYamlFile<MyConfigModel>(path, fileName);
    }
}

Create, Convert, and Update YAML Files

// Create YAML file
await _createYamlService.CreateYamlFileAsync(path, fileName, config);

// Convert file to YAML
string? yamlPath = await _convertToYamlService.ConvertFileToYamlAsync(filePath);

// Convert text to YAML in memory
string? yaml = await _convertToYamlService.ConvertTextToYamlInMemoryAsync(text);

// Update (merge), overwrite, or add to YAML file
await _updateYamlService.UpdateYamlFileAsync(path, fileName, data);
await _updateYamlService.OverwriteYamlFileAsync(path, fileName, data);
await _updateYamlService.AddToYAMLFileAsync(path, fileName, data);

Error Handling

  • All errors are logged using ILogger and SQS.
  • Service methods handle exceptions and provide diagnostics.

Requirements

  • .NET 8.0 or later

License

MIT License

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Davasorus.Utility.DotNet.Config:

Package Downloads
SA.OpenSearchTool.Business

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2026.2.2.14 47 5/17/2026
2026.2.2.13 44 5/15/2026
2026.2.2.12 105 5/10/2026
2026.2.2.11 100 5/6/2026
2026.2.2.10 92 5/5/2026
2026.2.2.9 90 5/5/2026
2026.2.2.8 98 5/4/2026
2026.2.2.7 84 5/4/2026
2026.2.2.6 96 5/3/2026
2026.2.2.5 91 5/2/2026
2026.2.2.4 104 5/2/2026
2026.2.2.3 92 5/2/2026
2026.2.2.2 89 5/1/2026
2026.2.2.1 97 5/1/2026
2026.2.1.4 119 4/16/2026
2026.2.1.3 853 4/11/2026
2026.2.1.2 142 4/9/2026
2026.2.1.1 158 4/1/2026
2026.1.3.5 101 3/29/2026
2026.1.3.4 110 3/24/2026
Loading failed