OpenLibs.Extensions 1.2.0

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

OpenLibs.Extensions

NuGet Downloads

Useful extensions for strongly-typed configuration and dependency injection in .NET applications.

🚀 Installation

dotnet add package OpenLibs.Extensions

📋 Features

SettingsConfigurationExtensions

Extensions to simplify strongly-typed settings configuration in .NET applications with built-in validation support.

Quick Usage Examples
public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        // Option 1: Register settings for dependency injection
        services.RegisterSettings<MySettings>(Configuration, "MyApp");
        
        // Option 2: Get validated settings instance immediately  
        var settings = services.ConfigureRequiredSettings<MySettings>(Configuration, "MyApp");
        
        // Option 3: Use fluent builder for advanced configuration
        services.ConfigureSettings<MySettings>(Configuration, "MyApp")
            .WithDataAnnotationValidation()
            .WithEagerValidation()
            .Register();
    }
}

[DataContract]
public class MySettings
{
    [Required]
    public string ApiUrl { get; set; } = string.Empty;
    
    [Range(1, 300)]
    public int TimeoutSeconds { get; set; }
}

SettingsConfigurationBuilder

Fluent builder pattern for advanced settings configuration with validation options.

Builder Usage Example
// Basic fluent configuration
services.ConfigureSettings<MySettings>(Configuration, "MyApp")
    .WithDataAnnotationValidation()  // Enable Data Annotations validation
    .WithEagerValidation()           // Validate at startup, not first access
    .Register();                     // Register in DI container

// Get settings instance directly
var settings = services.ConfigureSettings<MySettings>(Configuration, "MyApp")
    .WithDataAnnotationValidation()
    .Build();

🔧 Configuration

appsettings.json

{
  "MyApp": {
    "ApiUrl": "https://api.example.com",
    "TimeoutSeconds": 30
  }
}

Usage in Your Services

// Inject as IOptions<T>
public class MyService
{
    private readonly MySettings _settings;
    
    public MyService(IOptions<MySettings> settings)
    {
        _settings = settings.Value;
    }
}

📖 API Reference

SettingsConfigurationExtensions

RegisterSettings<T>(IServiceCollection, IConfiguration, string)

Registers a configuration object in the DI container with validation.

Parameters:

  • services: Service collection
  • configuration: IConfiguration instance
  • sectionName: Configuration section name

Returns: IServiceCollection for method chaining

ConfigureRequiredSettings<T>(IServiceCollection, IConfiguration, string)

Gets a validated settings instance immediately.

Returns: Validated instance of type T

ConfigureSettings<T>(IServiceCollection, IConfiguration, string)

Creates a fluent configuration builder.

Returns: SettingsConfigurationBuilder<T> for fluent configuration

SettingsConfigurationBuilder<T>

WithDataAnnotationValidation()

Enables automatic validation using Data Annotations attributes like [Required], [Range], etc.

WithEagerValidation()

Enables validation at application startup instead of first access.

Build()

Returns the configured settings instance.

Register()

Registers the settings in the DI container and returns the service collection.

🤝 Contributing

See the main project's contribution guide.

📄 License

This project is licensed under the MIT License.

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

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.2.0 210 7/30/2025