Lyo.Validation
2.0.0
dotnet add package Lyo.Validation --version 2.0.0
NuGet\Install-Package Lyo.Validation -Version 2.0.0
<PackageReference Include="Lyo.Validation" Version="2.0.0" />
<PackageVersion Include="Lyo.Validation" Version="2.0.0" />
<PackageReference Include="Lyo.Validation" />
paket add Lyo.Validation --version 2.0.0
#r "nuget: Lyo.Validation, 2.0.0"
#:package Lyo.Validation@2.0.0
#addin nuget:?package=Lyo.Validation&version=2.0.0
#tool nuget:?package=Lyo.Validation&version=2.0.0
Lyo.Validation
Fluent rule builders, C# validators, 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 + attributes.
PropertyValidatorBuilder<T, TProperty>/ValidatorBuilder<T>andAttributeValidator<T>. - Schema documents.
ValidationSchemakeyed by name, optional target type,WhereClauseconstraints (NotIn,In,Regex, and similar). - Store.
IValidationSchemaStore(in-memory default. Postgres in a sibling package). - Error mapping.
WhereClauseExplainResult.ToErrorsin Query.Models (not a Validation-local builder).
Examples
Usual 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 });
Validate via attributes
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 schema built from WhereClause
services.AddLyoQueryServices();
services.AddValidation();
services.AddQueryValidationEvaluator();
// or services.AddPostgresValidationStoreFromConfiguration(configuration);
var validator = await compiler.GetAsync<CreateUserRequest>("signup.v2", ct);
var result = validator.Validate(request);
Package contents
- Fluent validator composition via
PropertyValidatorBuilder<T, TProperty>andValidatorBuilder<T>(includingNotIn/Infor scalar allow-lists). - Attribute-based validation through built-in attributes such as
NotEmpty,Required,NotWhiteSpace,Length,Regex,Phone,Email,Uri, andRange(inLyo.Validation.Attributes). - Data-driven
ValidationSchemadocuments: a namedWhereClausetree (same operators as query filters) compiled toIValidator<T>viaIValidationSchemaCompiler. AttributeValidator<T>for reflection-driven validation across both Lyo'sValidationAttributeBaseandSystem.ComponentModel.DataAnnotations(includingIValidatableObject).- Structured property metadata via
ValidationMetadataKeys(AttemptedValue,PropertyName) attached to each failingError.Metadata. - Stable error codes via
Lyo.Result.ValidationErrorCodes(e.g.EmptyValue,NullValue,InvalidLength,InvalidEmail,OutOfRange,ValidationFailed).
Validate via attributes
Public instance-readable properties on T are what AttributeValidator<T> validates (compiled getters are cached statically per T). Lyo ValidationAttributeBase attributes run together with
System.ComponentModel.DataAnnotations.ValidationAttribute. When T is an IValidatableObject,
Validate(ValidationContext) runs as well. The cached singleton is AttributeValidator<T>.Shared; value.ValidateWithAttributes() is the call that uses it.
Lyo.Result.ValidationErrorCodes is where DataAnnotations codes land (RequiredAttribute → RequiredValue, EmailAddressAttribute → InvalidEmail,
RangeAttribute → OutOfRange). Unmapped attributes become ValidationFailed.
Schemas backed by a database
ValidationSchema is the wire DTO hosts PUT/GET on their own API. Constraints are a polymorphic WhereClause ($type: group / condition) using ComparisonOperatorEnum (In, Equals, 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.Core(direct, lyo)Lyo.Exceptions(direct, lyo)Lyo.Query.Evaluation(direct, lyo)Lyo.Query.Models(direct, lyo)Lyo.Result(direct, lyo)Lyo.Validation.Models(direct, lyo)Microsoft.Extensions.DependencyInjection.Abstractions10.0.5(direct, microsoft)System.ComponentModel.Annotations5.0.0(direct, microsoft)Lyo.Common.Json(transitive, lyo)Lyo.Common.Metadata(transitive, lyo)Lyo.Metrics(transitive, lyo)Lyo.Parameters(transitive, lyo)Microsoft.Bcl.AsyncInterfaces10.0.5(transitive, microsoft, netstandard2.0)System.Memory4.6.3(transitive, microsoft, netstandard2.0)System.Text.Json10.0.5(transitive, microsoft, netstandard2.0)
| Product | Versions 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. |
-
.NETStandard 2.0
- Lyo.Common.Core (>= 2.0.0)
- Lyo.Exceptions (>= 2.0.0)
- Lyo.Query.Evaluation (>= 2.0.0)
- Lyo.Query.Models (>= 2.0.0)
- Lyo.Result (>= 2.0.0)
- Lyo.Validation.Models (>= 2.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.5)
- System.ComponentModel.Annotations (>= 5.0.0)
-
net10.0
- Lyo.Common.Core (>= 2.0.0)
- Lyo.Exceptions (>= 2.0.0)
- Lyo.Query.Evaluation (>= 2.0.0)
- Lyo.Query.Models (>= 2.0.0)
- Lyo.Result (>= 2.0.0)
- Lyo.Validation.Models (>= 2.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.5)
- System.ComponentModel.Annotations (>= 5.0.0)
NuGet packages (6)
Showing the top 5 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.Config
Typed configuration definitions and per-entity bindings using flexible EntityRef references and JSON-backed values. |
|
|
Lyo.Validation.Postgres
PostgreSQL persistence for Lyo.Validation schemas (WhereClause JSONB) using Entity Framework Core. |
|
|
Lyo.Web.Primitives
MudBlazor UI primitives shared by every Lyo component package: chips, record cards, responsive layout, workbench shell, and browser interop. |
GitHub repositories
This package is not used by any popular GitHub repositories.