StaticNorth.Valiant.Validation 1.1.0

dotnet add package StaticNorth.Valiant.Validation --version 1.1.0
                    
NuGet\Install-Package StaticNorth.Valiant.Validation -Version 1.1.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="StaticNorth.Valiant.Validation" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="StaticNorth.Valiant.Validation" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="StaticNorth.Valiant.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 StaticNorth.Valiant.Validation --version 1.1.0
                    
#r "nuget: StaticNorth.Valiant.Validation, 1.1.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 StaticNorth.Valiant.Validation@1.1.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=StaticNorth.Valiant.Validation&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=StaticNorth.Valiant.Validation&version=1.1.0
                    
Install as a Cake Tool

Valiant Validation

Valiant Validation is a source-generated validation library for .NET. It keeps validation authoring small and explicit while generating direct runtime code that is friendly to trimming, Native AOT, and dependency injection without reflection-based assembly scanning.

Packages

  • StaticNorth.Valiant.Validation provides the runtime API and source generator.
  • StaticNorth.Valiant.Validation.AspNetCore adds Minimal API, MVC, and problem-details integration.
  • StaticNorth.Valiant.Validation.AspNetCore.OpenApi adds native ASP.NET Core OpenAPI schema integration.
  • StaticNorth.Valiant.Validation.MediatR adds a MediatR pipeline behavior. It intentionally pins MediatR to 12.5.0, the final free MediatR release.
  • StaticNorth.Valiant.Validation.Mediator adds the equivalent behavior for the source-generated Mediator package.

Install the most specific package your application uses. Integration packages forward StaticNorth.Valiant.Validation runtime, build, and analyzer assets, so a separate StaticNorth.Valiant.Validation package reference is not required for validator generation. Reference multiple integration packages when using multiple integrations, such as ASP.NET Core validation and OpenAPI.

Quick Start

using StaticNorth.Valiant.Validation;

[ValiantValidator]
public sealed partial class CreateUserValidator : ValidatorDefinition<CreateUser>
{
    public override void Configure(ValidationContext<CreateUser> context)
    {
        context.Property(user => user.Name)
            .Required()
            .MaxLength(64);

        context.Property(user => user.Age)
            .GreaterThanOrEqualTo(18);
    }
}

The generator emits an IValidator<CreateUser> implementation with direct property reads and native branch checks. When Microsoft.Extensions.DependencyInjection is available, it also emits AddValiantValidators(...):

services.AddValiantValidators(options =>
{
    options.Mode = ValiantValidationMode.Auto;
    options.Lifetime = ValiantValidatorLifetime.Scoped;
    options.FailureBehavior = ValiantFailureBehavior.ValidateAll;
});

Validation Status

Use Validate(...) or ValidateAsync(...) when callers need failure codes, messages, property names, and severity partitions. In Fast mode, generated validators build that diagnostic result lazily and avoid allocating a result builder for valid inputs.

Use IsValid(...) or IsValidAsync(...) when callers only need the validity status. The generated Fast path evaluates rule conditions, predicates, severities, and reused validators directly without constructing failure objects. Because diagnostics are not requested, failure code, message, and property-name expressions are not evaluated. Warning-only results are valid; errors and unknown severity values are invalid.

Debuggable mode keeps the materialized runtime path so user-authored configuration and diagnostic expressions remain available to the debugger.

Fluent Rules

Validators inherit ValidatorDefinition<T> and override Configure to declare rules through ValidationContext<T>:

public override void Configure(ValidationContext<CreateUser> context)
{
    if (context.Instance.RequiresInvite)
    {
        context.Property(user => user.InviteCode).Required();
    }

    context.Property(user => user.Email)
        .Required()
        .MaxLength(254);
}

In Debuggable mode, the user-authored Configure method executes at runtime, so breakpoints in native if, else, and switch statements work normally.

Attribute Rules

Validators can also derive from ValidatorDefinition<T> when model attributes should define the default rules:

using StaticNorth.Valiant.Validation;

[ValiantValidator]
public sealed partial class CreateUserValidator : ValidatorDefinition<CreateUser>;

public sealed class CreateUser
{
    [Required("NameRequired", "Name is required.")]
    [MaxLength(64)]
    public string? Name { get; init; }
}

Validation attributes are Valiant attributes, not System.ComponentModel.DataAnnotations. They use the same rule names and generated logic as fluent rules.

Reuse

Whole-model validators can be reused from another validator:

public void Configure(ValidationContext<CreateUser> context)
{
    context.UseValidator(_nameValidator);
    context.Property(user => user.Age).GreaterThanOrEqualTo(18);
}

Property validators derive from PropertyValidatorDefinition<TProperty> and can be applied to property values:

public void Configure(ValidationContext<CreateUser> context)
{
    context.Property(user => user.Address).UseValidator(_addressValidator);
}

Property validators skip null property values. Add Required() before UseValidator(...) when the property itself must be present.

ASP.NET Core

StaticNorth.Valiant.Validation.AspNetCore integrates generated validators with Minimal APIs, MVC, and validation problem responses.

builder.Services.AddValiantValidators();
builder.Services.AddValiantMvcValidation();

StaticNorth.Valiant.Validation.AspNetCore.OpenApi maps generated validation metadata into native ASP.NET Core OpenAPI schema constraints and x-valiant-rules extensions:

builder.Services.AddValiantValidators();
builder.Services.AddValiantOpenApi();

Mediator

StaticNorth.Valiant.Validation.MediatR and StaticNorth.Valiant.Validation.Mediator add pipeline behavior integration:

services.AddMediatR(configuration =>
{
    configuration.AddValiantValidation();
});
services.AddMediator(options =>
{
    options.Assemblies = [typeof(CreateUserCommand).Assembly];
});

services.AddValiantMediatorValidation();

For NativeAOT, configure the source-generated Mediator pipeline directly:

services.AddMediator(options =>
{
    options.Assemblies = [typeof(CreateUserCommand).Assembly];
    options.PipelineBehaviors = [typeof(ValiantValidationBehavior<,>)];
});

Use one Mediator registration path for the Valiant behavior. Do not also call AddValiantMediatorValidation() when ValiantValidationBehavior<,> is listed in PipelineBehaviors.

Benchmarks

The standalone StaticNorth.Valiant.Validation.Benchmarks project measures the generated Fast path for valid, one-failure, and all-failure inputs, with Validly as a pinned relative control. Its README documents correctness checks and the repeatable before/after workflow.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (5)

Showing the top 5 NuGet packages that depend on StaticNorth.Valiant.Validation:

Package Downloads
StaticNorth.Valiant.Settings.Validation

Options validation integration between Valiant Settings and Valiant Validation.

StaticNorth.Valiant.Validation.AspNetCore

ASP.NET Core integration helpers for Valiant validation.

StaticNorth.Valiant.Validation.Mediator

Source-generated Mediator pipeline behavior integration for Valiant validation.

StaticNorth.Valiant.Validation.AspNetCore.OpenApi

Native ASP.NET Core OpenAPI integration for Valiant validation metadata.

StaticNorth.Valiant.Validation.MediatR

MediatR pipeline behavior integration for Valiant validation.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.0 189 7/30/2026
1.0.1 184 7/26/2026