Configuration.Utils 1.0.0

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

Configuration.Utils

This is a library/package focused on functionalities related to the validation of the application's configuration.

Table of Content

Features

  • Object Validations: Allows efficient and fast validation of objects that use DataAnnotations in their class.
  • Custom Message: Once an object is validated and an error is found, the message provided offers a clean and good message.

Installation

You can install the library/package using NuGet. Open the terminal and execute the following command:

dotnet add package Configuration.Utils

Usage / Implementation

This is an example focused on validating values to be replaced in the project's configuration

Assuming you have the following values in your appsettings.json:

{
  "CoreSettings": {
    "Host": "https://example.com"
  }
}

And also, you have the following Settings class:

using System.ComponentModel.DataAnnotations;

public class CoreSettings
{
    [Required(ErrorMessage = "Core Host must be configured")]
    public string Host { get; init; } = string.Empty;

    [Required(ErrorMessage = "Core Port must be configured")]
    public int Port { get; init; }
}

You can then proceed to use the extension in your Program.cs file:

using Configuration.Utils;

builder.Services.Configure<CoreSettings>(builder.Configuration.GetSection("CoreSettings"));
builder.Configuration.ValidateConfiguration<CoreSettings>("CoreSettings"); // Defined Extension Method

The ValidateConfiguration method is implemented in ConfigurationValidationExtension, and in this case it would throw an exception of type InvalidConfigurationException with a message like the following:

Invalid Configuration for '{CoreSettings}':

- Core Port must be configured

Contribution

Contributions are welcome! Please fork the repository and submit a pull request.

Test

This project uses xUnit for Unit Tests.

To run the tests:

cd src\Configuration.Utils.Tests
dotnet test
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

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.0.0 189 7/20/2025
0.1.0 182 7/20/2025