Lyo.Validation 1.0.1

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

Lyo.Validation

Lyo.Validation contains reusable C# validators, fluent rule builders, validation attributes, and adapters that return structured Lyo.Result.Result<T> failures. Errors are populated through Lyo.Result.Error so callers can render Problem Details, log structurally, or aggregate into BulkResult.

Schemas are named WhereClause documents (ValidationSchema) that hosts load from an API or Lyo.Validation.Postgres. Evaluation reuses IWhereClauseService.ExplainMatch; failed nodes become errors via WhereClauseExplainResult.ToErrors.

Features

  • Fluent + attributesValidatorBuilder<T> / PropertyValidatorBuilder<T, TProperty> and AttributeValidator<T>
  • Schema documentsValidationSchema keyed by name, optional target type, WhereClause constraints (In, NotIn, Regex, …)
  • Pluggable storeIValidationSchemaStore (in-memory default; Postgres in a sibling package)
  • Shared error mappingWhereClauseExplainResult.ToErrors in Query.Models (not a Validation-local builder)

Examples

Typical usage

using Lyo.Validation;

var validator = ValidatorBuilder<CreateUserRequest>.Create()
    .RuleFor(x => x.Name)
    .NotWhiteSpace()
    .Length(2, 50)
    .RuleFor(x => x.Email)
    .Email()
    .RuleFor(x => x.Age)
    .InclusiveBetween(18, 120)
    .Build();

var result = validator.Validate(new CreateUserRequest { Name = "Matt", Email = "matt@example.com", Age = 33 });

Attribute-based validation

public sealed class CreateUserRequest {
    [NotWhiteSpace]
    [Length(2, 50)]
    public string Name { get; init; } = string.Empty;

    [Email]
    public string Email { get; init; } = string.Empty;

    [Range(18, 120)]
    public int Age { get; init; }
}

Result<CreateUserRequest> result = new CreateUserRequest { /* ... */ }.ValidateWithAttributes();

Load a WhereClause schema

services.AddLyoQueryServices();
services.AddValidation();
services.AddQueryValidationEvaluator();
// or services.AddPostgresValidationStoreFromConfiguration(configuration);

var validator = await compiler.GetAsync<CreateUserRequest>("signup.v2", ct);
var result = validator.Validate(request);

What lives here

  • Fluent validator composition via ValidatorBuilder<T> and PropertyValidatorBuilder<T, TProperty> (including In / NotIn for scalar allow-lists).
  • Attribute-based validation through built-in attributes such as Required, NotEmpty, NotWhiteSpace, Length, Regex, Email, Phone, Uri, and Range (in Lyo.Validation.Attributes).
  • Data-driven ValidationSchema documents: a named WhereClause tree (same operators as query filters) compiled to IValidator<T> via IValidationSchemaCompiler.
  • AttributeValidator<T> for reflection-driven validation across both Lyo's ValidationAttributeBase and System.ComponentModel.DataAnnotations (including IValidatableObject).
  • Structured property metadata via ValidationMetadataKeys (PropertyName, AttemptedValue) attached to each failing Error.Metadata.
  • Stable error codes via Lyo.Result.ValidationErrorCodes (e.g. NullValue, EmptyValue, InvalidLength, InvalidEmail, OutOfRange, ValidationFailed).

Attribute-based validation

AttributeValidator<T> reads validation attributes from T's public, instance-readable properties (compiled property getters are cached statically per T). It composes Lyo's own ValidationAttributeBase attributes with System.ComponentModel.DataAnnotations.ValidationAttribute, and — when T implements IValidatableObject — also runs Validate(ValidationContext). AttributeValidator<T>.Shared exposes a cached singleton; convenience extension value.ValidateWithAttributes() calls it.

DataAnnotations error codes are mapped onto Lyo.Result.ValidationErrorCodes (e.g. RequiredAttributeRequiredValue, EmailAddressAttributeInvalidEmail, RangeAttributeOutOfRange); anything not mapped falls back to ValidationFailed.

Database-backed schemas

ValidationSchema is the wire DTO hosts PUT/GET on their own API. Constraints are a polymorphic WhereClause ($type: condition / group) using ComparisonOperatorEnum (Equals, In, NotIn, Regex, …). An instance is valid iff the query engine reports a match.

Register AddValidation() plus AddQueryValidationEvaluator() (after AddLyoQueryServices()). Persist with Lyo.Validation.Postgres (AddPostgresValidationStoreFromConfiguration). WhereClauseValidator<T> calls ExplainMatch then ToErrors — do not add a second error mapper in API code.

Dependencies

Generated from ProjectReference / PackageReference (same model as docs/Lyo.ProjectGraph.html).

  • Lyo.Common — (direct, lyo)
  • Lyo.Exceptions — (direct, lyo)
  • Lyo.Query — (direct, lyo)
  • Lyo.Query.Models — (direct, lyo)
  • Lyo.Result — (direct, lyo)
  • Microsoft.Extensions.DependencyInjection.Abstractions 10.0.5 — (direct, microsoft)
  • System.ComponentModel.Annotations 5.0.0 — (direct, microsoft)
  • Lyo.Cache — (transitive, lyo)
  • Lyo.Compression — (transitive, lyo)
  • Lyo.Encryption — (transitive, lyo)
  • Lyo.Hashing — (transitive, lyo)
  • Lyo.Health — (transitive, lyo)
  • Lyo.KeyStore — (transitive, lyo)
  • Lyo.Metrics — (transitive, lyo)
  • Lyo.Streams — (transitive, lyo)
  • BouncyCastle.Cryptography 2.6.2 — (transitive, third-party, netstandard2.0)
  • EasyCompressor 2.1.0 — (transitive, third-party)
  • Konscious.Security.Cryptography.Argon2 1.3.1 — (transitive, third-party)
  • Microsoft.Bcl.AsyncInterfaces 10.0.5 — (transitive, microsoft, netstandard2.0)
  • Microsoft.Extensions.Caching.Memory 10.0.5 — (transitive, microsoft)
  • Microsoft.Extensions.Configuration.Binder 10.0.5 — (transitive, microsoft)
  • Microsoft.Extensions.DependencyInjection 10.0.5 — (transitive, microsoft)
  • Microsoft.Extensions.Logging.Abstractions 10.0.5 — (transitive, microsoft)
  • Microsoft.Extensions.Options.ConfigurationExtensions 10.0.5 — (transitive, microsoft)
  • System.Buffers 4.6.1 — (transitive, microsoft, netstandard2.0)
  • System.IO.Hashing 10.0.5 — (transitive, microsoft, net10.0)
  • System.Memory 4.6.3 — (transitive, microsoft, netstandard2.0)
  • System.Text.Json 10.0.5 — (transitive, microsoft, netstandard2.0)
  • System.Threading.Tasks.Extensions 4.6.3 — (transitive, microsoft, netstandard2.0)
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 was computed.  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 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. 
.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 (3)

Showing the top 3 NuGet packages that depend on Lyo.Validation:

Package Downloads
Lyo.Web.Components

Blazor components library for the Lyo web UI framework with MudBlazor integration.

Lyo.Api

Core API library for building RESTful APIs with Entity Framework Core, caching, and mapping support.

Lyo.Validation.Postgres

PostgreSQL persistence for Lyo.Validation schemas (WhereClause JSONB) using Entity Framework Core.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 34 8/18/2026
1.0.0 205 8/16/2026