MessageValidation.FluentValidation 0.3.0

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

MessageValidation.FluentValidation

FluentValidation adapter for the MessageValidation pipeline — automatically bridge your existing FluentValidation validators into the protocol-agnostic message validation pipeline.

Installation

dotnet add package MessageValidation.FluentValidation

Quick Start

1. Define your message

public class TemperatureReading
{
    public string SensorId { get; set; } = "";
    public double Value { get; set; }
    public DateTime Timestamp { get; set; }
}

2. Create a FluentValidation validator

Write a standard FluentValidation AbstractValidator<T> — no special base class required:

using FluentValidation;

public class TemperatureReadingValidator : AbstractValidator<TemperatureReading>
{
    public TemperatureReadingValidator()
    {
        RuleFor(x => x.SensorId).NotEmpty();
        RuleFor(x => x.Value).InclusiveBetween(-50, 150);
        RuleFor(x => x.Timestamp).LessThanOrEqualTo(DateTime.UtcNow);
    }
}

3. Register services

using MessageValidation;
using MessageValidation.FluentValidation;

builder.Services.AddMessageValidation(options =>
{
    options.MapSource<TemperatureReading>("sensors/+/temperature");
    options.DefaultFailureBehavior = FailureBehavior.Log;
});

// Scan the assembly for all AbstractValidator<T> implementations
// and register the FluentValidation adapter as the IMessageValidator<T> bridge.
builder.Services.AddMessageFluentValidation(typeof(Program).Assembly);

builder.Services.AddMessageDeserializer<JsonMessageDeserializer>();
builder.Services.AddMessageHandler<TemperatureReading, TemperatureHandler>();

That's it. The pipeline will now use your TemperatureReadingValidator automatically when a TemperatureReading message arrives.

How It Works

AddMessageFluentValidation does two things:

  1. Scans assemblies for all AbstractValidator<T> implementations and registers them in the DI container (via FluentValidation.DependencyInjectionExtensions).
  2. Registers an open-generic adapter (FluentValidationMessageValidator<T>) that implements IMessageValidator<T> by delegating to FluentValidation's IValidator<T>.
IMessageValidator<T>
    └── FluentValidationMessageValidator<T>
            └── IValidator<T>  (your AbstractValidator<T>)

API Reference

AddMessageFluentValidation(params Assembly[] assemblies)

Parameter Description
assemblies Assemblies to scan for AbstractValidator<T> implementations. If none are provided, the calling assembly is scanned.
// Scan specific assemblies
builder.Services.AddMessageFluentValidation(
    typeof(TemperatureReadingValidator).Assembly,
    typeof(DeviceHeartbeatValidator).Assembly);

// Or scan the calling assembly (default)
builder.Services.AddMessageFluentValidation();

Requirements

License

MIT

Product Compatible and additional computed target framework versions.
.NET 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

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.0.0 88 4/1/2026
0.3.0 85 3/25/2026
0.2.0 89 3/9/2026
0.1.0-preview.1 42 3/4/2026