Lukdrasil.Validation.Fluent
1.0.0
dotnet add package Lukdrasil.Validation.Fluent --version 1.0.0
NuGet\Install-Package Lukdrasil.Validation.Fluent -Version 1.0.0
<PackageReference Include="Lukdrasil.Validation.Fluent" Version="1.0.0" />
<PackageVersion Include="Lukdrasil.Validation.Fluent" Version="1.0.0" />
<PackageReference Include="Lukdrasil.Validation.Fluent" />
paket add Lukdrasil.Validation.Fluent --version 1.0.0
#r "nuget: Lukdrasil.Validation.Fluent, 1.0.0"
#:package Lukdrasil.Validation.Fluent@1.0.0
#addin nuget:?package=Lukdrasil.Validation.Fluent&version=1.0.0
#tool nuget:?package=Lukdrasil.Validation.Fluent&version=1.0.0
Lukdrasil.Validation
Lukdrasil.Validation is a .NET 8 library for functional and fluent validation, error handling, and result composition. It provides a robust, composable, and testable way to handle validation and error propagation in C# applications, including ASP.NET Core Minimal APIs. The solution consists of three projects:
- Validation: Core validation and result types.
- Validation.Fluent: Extensions for integration with FluentValidation.
- Validation.Tests: Unit tests for the validation logic.
Features
- Functional-style
ValidationResult<T>for success/failure flows - Composable error handling with
ValidationErrorandExtendedError - Minimal API integration for ASP.NET Core
- FluentValidation support for seamless rule validation
- Async/await support for validation chains
Getting Started
Installation
Add the NuGet package to your project:
Core validation
Install-Package Lukdrasil.Validation -Version x.y.z
FluentValidation integration
Install-Package Lukdrasil.Validation.Fluent -Version x.y.z
Basic Usage
Creating Validation Results
using Lukdrasil.Result;
var success = ValidationResult<string>.Success("Valid value");
var error = new ValidationError(new Error.Error("ERR001", "Invalid value"));
var failure = ValidationResult<string>.Failure(error);
#### Composing Results
var result1 = ValidationResult<string>.Success("A");
var result2 = ValidationResult<string>.Failure(new ValidationError(new Error.Error("ERR002", "Error B")));
var combined = result1.And(result2); // Combines errors if any
#### Pattern Matching
var output = result1.Match(
value => $"Success: {value}",
err => $"Failure: {string.Join(", ", err.Errors.Select(e => e.Description))}"
);
Minimal API Integration
app.MapPost("/validate", (MyModel model) =>
{
var result = ValidateModel(model);
return result.ToHttpResult<MyModel, ValidationResult<MyModel>>();
});
FluentValidation Integration
using Lukdrasil.Validation.Fluent;
using FluentValidation;
public class MyModelValidator : AbstractValidator<MyModel>
{
public MyModelValidator()
{
RuleFor(x => x.Name).NotEmpty();
}
}
var result = ValidationResult<MyModel>.Success(new MyModel { Name = "" })
.Validate<MyModel, MyModelValidator>();
if (!result.IsSuccess)
{
// Handle validation errors
}
Testing
Unit tests are provided in the Validation.Tests project. Run them using your preferred test runner:
dotnet test
Contributing
Contributions are welcome! Please open issues or submit pull requests for improvements and bug fixes.
License
This project is licensed under the MIT License. See the LICENSE file for details.
| Product | Versions 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. |
-
net9.0
- FluentValidation (>= 12.0.0)
- Lukdrasil.Error (>= 1.0.0)
- Lukdrasil.Result (>= 1.0.0)
- Lukdrasil.Validation (>= 1.0.0)
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 |
|---|