Crabalidator 1.0.0

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

Crabalidator

Build NuGet License

Crabalidator is a high-performance .NET validation library built on top of DynaBee runtime code generation.

Crabalidator is designed for applications that want FluentValidation-style validators, but prefer compiled runtime validation plans over reflection-heavy execution paths. Validators describe rules through a familiar fluent API, Crabalidator turns those rules into backend-neutral validation plans, and DynaBee generates executable validation methods for hot sync paths.

What Crabalidator Does

  • Configures validators with CrabValidator<T> and RuleFor(...).
  • Supports common sync rules such as NotEmpty, comparisons, equality, and custom Must(...) predicates.
  • Supports property-level When(...) and Unless(...) conditions.
  • Supports Cascade(CascadeMode.Stop) for fail-fast property validation.
  • Supports nested object validation through SetValidator(...).
  • Supports collection element validation through RuleForEach(...).
  • Supports async custom rules through MustAsync(...).
  • Supports async nested validators and cancellation.
  • Integrates with Microsoft.Extensions.DependencyInjection.
  • Provides ICrabalidator, typed IValidator<T>, and typed IAsyncValidator<T> runtime APIs.
  • Provides registered validator diagnostics and readable validation plan output through DescribePlan(...).
  • Uses DynaBee-generated method bodies and invokers for optimized sync validation paths.
  • Includes BenchmarkDotNet coverage against FluentValidation baselines.

Design Goals

Crabalidator is intentionally split from the generation engine.

Crabalidator owns:

  • validation configuration
  • validation planning
  • rule semantics
  • diagnostics
  • dependency injection
  • runtime validator registration
  • public validation APIs

DynaBee owns:

  • generated type creation
  • generated method body creation
  • generated method invocation
  • low-level runtime code generation details

This boundary keeps Crabalidator focused on validation behavior while allowing DynaBee to evolve as a general-purpose runtime generation engine.

Requirements

  • .NET SDK 10.0+ recommended for development.
  • The library multi-targets net8.0, net9.0, and net10.0.

Installation

Install Crabalidator from NuGet:

dotnet add package Crabalidator --version 1.0.0

For local development, reference the project directly or use the solution in this repository.

Quick Start

Define a validator:

using Crabalidator;

public sealed class CustomerValidator : CrabValidator<Customer>
{
    public CustomerValidator()
    {
        RuleFor(x => x.Name)
            .Cascade(CascadeMode.Stop)
            .NotEmpty()
            .MinimumLength(3);

        RuleFor(x => x.Age)
            .GreaterThanOrEqualTo(18);

        RuleFor(x => x.Email)
            .NotEmpty()
            .Must(value => value.Contains('@'));
    }
}

public sealed class Customer
{
    public string Name { get; set; }

    public int Age { get; set; }

    public string Email { get; set; }
}

Validate directly:

var validator = new CustomerValidator();
var result = validator.Validate(new Customer());

if (!result.IsValid)
{
    foreach (var failure in result.Errors)
    {
        Console.WriteLine($"{failure.PropertyName}: {failure.ErrorMessage}");
    }
}

Dependency Injection

Register Crabalidator with the assemblies that contain validators:

using Crabalidator;
using Crabalidator.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;

var services = new ServiceCollection();

services.AddCrabalidator(typeof(CustomerValidator).Assembly);

var provider = services.BuildServiceProvider();
var validator = provider.GetRequiredService<IValidator<Customer>>();

var result = validator.Validate(customer);

Applications that prefer a single service entry point can use ICrabalidator:

var crabalidator = provider.GetRequiredService<ICrabalidator>();

ValidationResult result = crabalidator.Validate(customer);

Conditions And Cascade

Conditions apply to the property rule chain:

RuleFor(x => x.ReferralCode)
    .NotEmpty()
    .When(x => x.RequiresReferral);

Use cascade stop to avoid running later validators for the same property after the first failure:

RuleFor(x => x.Name)
    .Cascade(CascadeMode.Stop)
    .NotEmpty()
    .MinimumLength(3);

Nested Validators

Validate child objects:

RuleFor(x => x.Address)
    .SetValidator(new AddressValidator());

Validate collection elements:

RuleFor(x => x.Items)
    .NotEmpty()
    .RuleForEach(new OrderItemValidator());

Nested failures are returned with prefixed paths such as Address.PostalCode or Items[0].Sku.

Async Validation

Use MustAsync(...) for async checks:

RuleFor(x => x.Username)
    .NotEmpty()
    .MustAsync(IsUsernameAvailableAsync);

static async ValueTask<bool> IsUsernameAvailableAsync(
    string username,
    CancellationToken cancellationToken)
{
    await Task.Delay(10, cancellationToken);
    return username != "taken";
}

Validators that contain async rules must be executed with ValidateAsync(...).

Diagnostics

Crabalidator can describe registered validators and generated validation plans:

using Crabalidator.Diagnostics;

var diagnostics = provider.GetRequiredService<ICrabalidatorDiagnostics>();

Console.WriteLine(diagnostics.DescribeRegisteredValidators());
Console.WriteLine(diagnostics.DescribePlan<Customer>());

Samples And Benchmarks

Run the basic sample:

dotnet run --project samples/Crabalidator.Samples.Basic

Run the test suite:

dotnet test

Run benchmarks:

dotnet run --project benchmarks/Crabalidator.Benchmarks -c Release

Release

Production releases are published from branches named releases/vX.Y.Z.

The release workflow validates the changelog, builds, tests, packs NuGet packages, creates or updates the GitHub release tag, creates the GitHub release, and publishes to nuget.org through NuGet Trusted Publishing.

The repository variable NUGET_USER must be set to the nuget.org username configured in the Trusted Publishing policy.

Documentation

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 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.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Crabalidator:

Package Downloads
TurtlePath.Crabalidator

Crabalidator adapter for TurtlePath validation contracts.

Crabalidator.Testing

Testing helpers for Crabalidator validators without a full application host.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.4 197 8/11/2026
1.0.3 409 8/7/2026
1.0.2 107 8/6/2026
1.0.1 466 7/22/2026
1.0.0 117 7/22/2026