Hexalith.Commons.Configurations 1.66.5

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

Hexalith.Commons.Configurations

Overview

Hexalith.Commons.Configurations is a .NET library that provides utilities for handling configuration settings in .NET applications. It simplifies the process of retrieving, validating, and managing configuration settings using Microsoft's configuration and options patterns.

Features

  • Interface-based configuration settings with ISettings
  • Helper methods for retrieving settings from configuration
  • FluentValidation integration for validating configuration options
  • Exception handling for configuration errors
  • Support for Microsoft's Options pattern

Installation

Package Manager Console

Install-Package Hexalith.Commons.Configurations

.NET CLI

dotnet add package Hexalith.Commons.Configurations

Usage

Defining Settings

using Hexalith.Commons.Configurations;

public class MyAppSettings : ISettings
{
    public string ConnectionString { get; set; } = string.Empty;
    public int Timeout { get; set; } = 30;
    
    public static string ConfigurationName() => "MyApp";
}

Retrieving Settings

using Hexalith.Commons.Configurations;

// Get settings using the helper method
MyAppSettings settings = configuration.GetSettings<MyAppSettings>();

Dependency Injection

Add the settings to the service collection and configure them using the ConfigureSettings method.

using Hexalith.Commons.Configurations;

// Register services
builder.Services.ConfigureSettings<MyAppSettings>(builder.Configuration);

Get a comprehensive error message on the invalid setting in your application.

using Hexalith.Commons.Configurations;

public class MyClass 
{
    private readonly string _connectionString;

    public MyClass(IOptions<MyAppSettings> options)
    {
        // Check if the options are valid and throw a detailed exception if not
        SettingsException<MyAppSettings>.ThrowIfUndefined(options.Value.ConnectionString);
        _connectionString = options.Value.ConnectionString;
    }
}

Validating Settings with FluentValidation

using FluentValidation;
using Hexalith.Commons.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;

// Create a validator for your settings
public class MyAppSettingsValidator : AbstractValidator<MyAppSettings>
{
    public MyAppSettingsValidator()
    {
        RuleFor(x => x.ConnectionString).NotEmpty();
        RuleFor(x => x.Timeout).GreaterThan(0);
    }
}

// Register settings with validation
services.ConfigureSettings<MyAppSettings>(configuration);

ISettings Interface

public interface ISettings
{
    // The name of the configuration section. For example, "MyApp:MySettings".
    static abstract string ConfigurationName();
}

The ISettings interface defines a contract for configuration settings classes. It requires implementing a static ConfigurationName() method that returns the name of the configuration section.

SettingsHelper Class

public static class SettingsHelper
{
    public static TSettings GetSettings<TSettings>(this IConfiguration configuration)
        where TSettings : class, ISettings, new();
}

The SettingsHelper class provides extension methods for retrieving settings from configuration.

FluentValidateOptions Class

public class FluentValidateOptions<TOptions> : IValidateOptions<TOptions>
    where TOptions : class
{
    public FluentValidateOptions(string? name, IServiceProvider provider);
    public ValidateOptionsResult Validate(string? name, TOptions options);
}

The FluentValidateOptions class implements IValidateOptions<TOptions> to provide FluentValidation integration for the Options pattern.

Dependencies

  • FluentValidation.DependencyInjectionExtensions
  • Microsoft.Extensions.Configuration.Binder
  • Microsoft.Extensions.Logging.Abstractions
  • Microsoft.Extensions.Options
  • Microsoft.Extensions.Options.ConfigurationExtensions
  • Microsoft.Extensions.Options.DataAnnotations

License

This project is licensed under the MIT License - see the LICENSE file in the project root for details.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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 (6)

Showing the top 5 NuGet packages that depend on Hexalith.Commons.Configurations:

Package Downloads
Hexalith.Security.Application

Hexalith is a set of libraries to build an application with micro-service architecture.

Hexalith.IdentityStores.Abstractions

Hexalith is a set of libraries to build an application with micro-service architecture.

Hexalith.DaprIdentityStore.Abstractions

Hexalith is a set of libraries to build a micro-service architecture.

Hexalith.KeyValueStorages.Abstractions

Hexalith KeyValueStorages utilities and helpers

Hexalith.KeyValueStorages.Files

Hexalith KeyValueStorages utilities and helpers

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.1.7 405 9/20/2025
2.1.6 262 8/10/2025
2.1.5 248 8/5/2025
2.1.4 1,111 7/24/2025
2.1.3 1,472 7/9/2025
2.1.2 793 7/6/2025
2.1.1 555 7/6/2025
2.1.0 166 7/6/2025
2.0.6 163 7/6/2025
2.0.5 661 7/4/2025
2.0.4 177 7/4/2025
2.0.3 586 6/29/2025
2.0.2 2,165 6/24/2025
2.0.1 1,723 6/13/2025
2.0.0 288 6/13/2025
1.66.5 1,625 4/11/2025
1.66.4 215 4/10/2025
1.66.3 446 4/9/2025
1.66.2 220 4/8/2025
1.66.1 171 4/8/2025
1.66.0 169 4/7/2025
1.65.1 172 4/6/2025
1.65.0 178 4/6/2025
1.64.0 560 4/2/2025
1.0.0 183 4/2/2025