Lukdrasil.Validation.Fluent 1.0.0

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package Lukdrasil.Validation.Fluent --version 1.0.0
                    
NuGet\Install-Package Lukdrasil.Validation.Fluent -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="Lukdrasil.Validation.Fluent" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Lukdrasil.Validation.Fluent" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Lukdrasil.Validation.Fluent" />
                    
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 Lukdrasil.Validation.Fluent --version 1.0.0
                    
#r "nuget: Lukdrasil.Validation.Fluent, 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 Lukdrasil.Validation.Fluent@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=Lukdrasil.Validation.Fluent&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Lukdrasil.Validation.Fluent&version=1.0.0
                    
Install as a Cake Tool

Lukdrasil.Validation

License: MIT

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 ValidationError and ExtendedError
  • 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 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