fl-configuration-extensions
0.3.1
dotnet add package fl-configuration-extensions --version 0.3.1
NuGet\Install-Package fl-configuration-extensions -Version 0.3.1
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="fl-configuration-extensions" Version="0.3.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="fl-configuration-extensions" Version="0.3.1" />
<PackageReference Include="fl-configuration-extensions" />
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 fl-configuration-extensions --version 0.3.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: fl-configuration-extensions, 0.3.1"
#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 fl-configuration-extensions@0.3.1
#: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=fl-configuration-extensions&version=0.3.1
#tool nuget:?package=fl-configuration-extensions&version=0.3.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Fl.Configuration.Extensions
A .NET library that provides functional programming extensions for Microsoft's Configuration system, offering type-safe configuration binding with functional programming patterns.
Features
- Type-Safe Configuration Binding: Automatically maps configuration sections to strongly-typed objects
- Functional Programming Support: Integration with LanguageExt Option monad for null-safe operations
- Convention-Based: Uses type name as configuration section key
- Dual APIs: Both strict (throws on missing) and safe (returns Option) configuration retrieval
- Multi-Framework Support: Targets .NET 8.0, 9.0, and 10.0
Installation
dotnet add package Fl.Configuration.Extensions
Usage
Configuration Class Setup
public record DatabaseConfig
{
public string ConnectionString { get; init; }
public int Timeout { get; init; }
}
Configuration File (appsettings.json)
{
"DatabaseConfig": {
"ConnectionString": "Server=localhost;Database=MyDb;",
"Timeout": 30
}
}
Required Configuration (Strict)
Use GetRequiredConfiguration<T>() when the configuration section must be present:
var dbConfig = configuration.GetRequiredConfiguration<DatabaseConfig>();
// Throws KeyNotFoundException if "DatabaseConfig" section is missing
Console.WriteLine($"Connection: {dbConfig.ConnectionString}");
Optional Configuration (Safe)
Use GetConfiguration<T>() for optional configuration sections:
var optionalConfig = configuration.GetConfiguration<DatabaseConfig>();
// Functional pattern matching:
optionalConfig.Match(
/* Some: */ config => {
Console.WriteLine($"Connection: {config.ConnectionString}");
// Use the configuration
},
/* None: */ () => {
Console.WriteLine("Configuration not found, using defaults");
// Handle missing configuration gracefully
}
);
// Or check if present:
if (optionalConfig.IsSome)
{
var config = optionalConfig.ValueUnsafe();
// Use config...
}
API Reference
Extension Methods
GetRequiredConfiguration<T>()
public static T GetRequiredConfiguration<T>(this IConfiguration configuration) where T : class, new()
- Returns: Instance of type
Tpopulated from configuration - Throws:
KeyNotFoundExceptionif the configuration section is missing - Section Key: Uses
typeof(T).Nameas the configuration section key
GetConfiguration<T>()
public static Option<T> GetConfiguration<T>(this IConfiguration configuration) where T : class, new()
- Returns:
Option<T>-Some<T>if found,Noneif missing - Section Key: Uses
typeof(T).Nameas the configuration section key - Safe: Never throws exceptions, use functional pattern matching
Dependencies
- Microsoft.Extensions.Configuration (≥10.0.3)
- Microsoft.Extensions.Configuration.Abstractions (≥10.0.3)
- Microsoft.Extensions.Configuration.Binder (≥10.0.3)
- Fl.Functional.Utils (≥0.1.0)
- LanguageExt: Functional programming library for Option monad
Target Frameworks
- .NET 8.0
- .NET 9.0
- .NET 10.0
Ideal Use Cases
- Microservices Architecture: Clean, type-safe configuration binding
- Functional Programming: Integration with functional codebases using LanguageExt
- Configuration Validation: Early detection of missing required configuration
- Optional Feature Configuration: Safe handling of optional configuration sections
- Strongly-Typed Configuration: Automatic mapping without manual binding code
Benefits
- Type Safety: Compile-time guarantees for configuration structure
- Functional Programming: Option monad prevents null reference exceptions
- Convention-Based: No magic strings, uses type names as section keys
- Clean API: Simple, expressive methods for common configuration patterns
- Multi-Framework: Supports latest .NET versions
| Product | Versions 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 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 is compatible. 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.
-
net10.0
- fl-functional-utils (>= 0.2.1)
- Microsoft.Extensions.Configuration (>= 10.0.7)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.7)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.7)
-
net8.0
- fl-functional-utils (>= 0.2.1)
- Microsoft.Extensions.Configuration (>= 10.0.7)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.7)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.7)
-
net9.0
- fl-functional-utils (>= 0.2.1)
- Microsoft.Extensions.Configuration (>= 10.0.7)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.7)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.7)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on fl-configuration-extensions:
| Package | Downloads |
|---|---|
|
fl-shared-utils-components
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.