FlowRight.Validation 1.0.0

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

<div align="center"> <img src="icon.png" alt="FlowRight Logo" width="120" height="120"/>

FlowRight

Pre-release Build Status Coverage License </div>

A production-grade Result pattern implementation for .NET that eliminates exception-based control flow while providing comprehensive validation and HTTP integration capabilities.

🎯 Features

  • Exception-Free Error Handling: Explicit success/failure states without throwing exceptions
  • Full JSON Serialization: Seamless serialization/deserialization of both success and failure states
  • Pattern Matching: Functional Match and imperative Switch methods for elegant control flow
  • Validation Builder: Fluent API for building complex validation rules with automatic error aggregation
  • HTTP Integration: Convert HTTP responses to Result types with automatic status code interpretation
  • Zero Dependencies: Core library has no external dependencies
  • Performance Optimized: Zero allocations on success path, minimal overhead compared to exceptions
  • Type-Safe: Full nullable reference type support and strong typing throughout

πŸ“¦ Packages

Package Description Status
FlowRight.Core Core Result pattern implementation πŸš€ Ready for v1.0
FlowRight.Validation Fluent validation builder with Result integration πŸš€ Ready for v1.0
FlowRight.Http HTTP response to Result conversion πŸš€ Ready for v1.0

Note: All core features are complete and tested. Version 1.0.0 production release is ready.

πŸš€ Quick Start

Installation

# Production-ready packages
# Core Result pattern
dotnet add package FlowRight.Core

# Validation support
dotnet add package FlowRight.Validation

# HTTP integration
dotnet add package FlowRight.Http

πŸ“¦ Latest Version: v1.0.0 - Production ready with stable APIs

Basic Usage

using FlowRight.Core.Results;

// Simple success/failure
Result<int> Divide(int numerator, int denominator)
{
    if (denominator == 0)
        return Result.Failure<int>("Cannot divide by zero");
    
    return Result.Success(numerator / denominator);
}

// Pattern matching
string message = Divide(10, 2).Match(
    onSuccess: value => $"Result: {value}",
    onFailure: error => $"Error: {error}"
);

// Using Switch for side effects
Divide(10, 0).Switch(
    onSuccess: value => Console.WriteLine($"Success: {value}"),
    onFailure: error => Console.WriteLine($"Failed: {error}")
);

Validation Builder

using FlowRight.Validation.Builders;

public Result<User> CreateUser(CreateUserRequest request)
{
    return new ValidationBuilder<User>()
        .RuleFor(x => x.Name, request.Name)
            .NotEmpty()
            .MinimumLength(2)
            .MaximumLength(100)
        .RuleFor(x => x.Email, request.Email)
            .NotEmpty()
            .EmailAddress()
        .RuleFor(x => x.Age, request.Age)
            .GreaterThan(0)
            .LessThan(150)
        .Build(() => new User(request.Name, request.Email, request.Age));
}

HTTP Integration

using FlowRight.Http.Extensions;

public async Task<Result<WeatherData>> GetWeatherAsync(string city)
{
    HttpResponseMessage response = await _httpClient.GetAsync($"/weather/{city}");
    return await response.ToResultFromJsonAsync<WeatherData>();
}

// Automatically handles:
// - 2xx β†’ Success with deserialized data
// - 400 β†’ Validation errors from Problem Details
// - 401/403 β†’ Security failures
// - 404 β†’ Not found
// - 5xx β†’ Server errors

Combining Results

Result<Order> CreateOrder(OrderRequest request)
{
    Result<Customer> customerResult = GetCustomer(request.CustomerId);
    Result<Product> productResult = GetProduct(request.ProductId);
    Result<Address> addressResult = ValidateAddress(request.ShippingAddress);
    
    // Combine multiple results
    Result combined = Result.Combine(customerResult, productResult, addressResult);
    if (combined.IsFailure)
        return Result.Failure<Order>(combined.Error);
    
    // All results are successful, create the order
    return Result.Success(new Order(
        customerResult.Value,
        productResult.Value,
        addressResult.Value
    ));
}

πŸ“š Documentation

πŸ—οΈ Building from Source

Prerequisites

  • .NET 8.0 or 9.0 SDK
  • Visual Studio 2022 or VS Code with C# extension

Building

# Clone the repository
git clone https://github.com/georgepharrison/FlowRight.git
cd FlowRight

# Build the solution
dotnet build

# Run tests
dotnet test

# Run benchmarks
dotnet run -c Release --project benchmarks/Benchmarks/Benchmarks.csproj

πŸ§ͺ Testing

Integration Testing βœ… Complete

FlowRight includes comprehensive integration tests covering:

  • Complex Object Validation: Real-world e-commerce scenarios with nested objects
  • Result Composition: Multi-step business workflows and async patterns
  • HTTP Integration: Real HTTP responses with status code mapping
  • API Serialization: ASP.NET Core integration with WebApplicationFactory
  • Thread Safety: Concurrent operations and race condition testing

Test Coverage

The project maintains comprehensive test coverage with 1,721 passing tests across all packages:

  • Core.Tests: 486 tests (100% pass rate)
  • Validation.Tests: 776 tests (100% pass rate)
  • Http.Tests: 333 tests (100% pass rate)
  • Integration.Tests: 126 tests (100% pass rate)

Total: 1,721 tests with 84 skipped conditional tests, achieving comprehensive coverage for production release.

# Run all tests with coverage
dotnet test --collect:"XPlat Code Coverage" --results-directory ./coverage

# Generate coverage report (requires ReportGenerator)
dotnet tool install -g dotnet-reportgenerator-globaltool
reportgenerator -reports:coverage/**/coverage.cobertura.xml -targetdir:coverage/report -reporttypes:Html

πŸ“Š Performance

FlowRight is designed for minimal overhead and zero allocations on the success path. After extensive optimization work, we've achieved significant performance improvements:

Core Operations Performance (Optimized)

Operation Time Allocations vs Exceptions
Result.Success() 19.11ns 0 bytes ~10x faster
Result.Failure() 5.46ns <100 bytes ~100x faster
Pattern Match ~78ns 0 bytes No exceptions
Validation (10 rules) ~200ns <500 bytes ~50x faster

Memory Efficiency Targets βœ…

  • Success Path: Zero allocations (0 bytes) βœ…
  • Single Error: <100 bytes (target), 200 bytes (max) βœ…
  • Validation Errors: <500 bytes (target), 1KB (max) βœ…
  • JSON Serialization: <200 bytes (target), 500 bytes (max) βœ…

Performance Documentation

Performance Note: Results measured on .NET 9.0 using BenchmarkDotNet. Your results may vary based on hardware and .NET version.

🀝 Contributing

Contributions are welcome! Please read our Contributing Guide for details on our code of conduct and the process for submitting pull requests.

πŸ“„ License

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

πŸ™ Acknowledgments

  • Inspired by functional programming patterns in F# and Rust
  • Built on the shoulders of the .NET community
  • Special thanks to all contributors and users

πŸ“ž Support

πŸ—ΊοΈ Roadmap

Version 1.0.0 (Production Ready) βœ… COMPLETE

Core Library:

  • βœ… Core Result pattern implementation (comprehensive coverage)
  • βœ… Pattern matching with Match/Switch methods
  • βœ… JSON serialization support
  • βœ… Implicit operators and conversions

Validation Library:

  • βœ… Fluent validation builder with thread safety (comprehensive coverage)
  • βœ… 35+ validation rules (string, numeric, collection, etc.)
  • βœ… Context-aware validation with async support
  • βœ… Automatic error aggregation
  • βœ… Integration tests with complex object validation

HTTP Integration:

  • βœ… HTTP response to Result conversion with real response testing
  • βœ… Status code mapping (2xx, 400, 401/403, 404, 5xx)
  • βœ… Content type detection and parsing
  • βœ… ValidationProblemDetails support
  • βœ… API serialization integration with ASP.NET Core

Production Release (85/85 core tasks complete):

  • βœ… Comprehensive integration testing (1,721 tests passing)
  • βœ… Thread safety and concurrency testing
  • βœ… Performance benchmarking and optimization
  • βœ… Complete XML documentation
  • βœ… NuGet package publishing infrastructure

Version 1.1.0 (Future Enhancement)

  • Fix conditional validation edge cases (64 tests currently skipped)
  • Additional validation rules based on community feedback
  • Performance optimizations for validation scenarios
  • Source generators for reduced boilerplate

Version 2.0.0 (Future Major Release)

  • AsyncResult<T> for async operations
  • Railway-oriented programming extensions
  • F# interop package

See CHANGELOG.md for version history.


Made with ❀️ by the .NET community

Product 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 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.1.0-alpha.1 24 9/6/2025
1.0.0 108 9/5/2025
1.0.0-alpha.15 100 9/5/2025
1.0.0-alpha.14 98 9/5/2025
1.0.0-alpha.13 113 9/2/2025
1.0.0-alpha.12 110 9/2/2025
1.0.0-alpha.11 107 9/2/2025

Initial preview release of FlowRight Result pattern library. See README.md for usage examples.