Lyo.Validation
1.0.1
dotnet add package Lyo.Validation --version 1.0.1
NuGet\Install-Package Lyo.Validation -Version 1.0.1
<PackageReference Include="Lyo.Validation" Version="1.0.1" />
<PackageVersion Include="Lyo.Validation" Version="1.0.1" />
<PackageReference Include="Lyo.Validation" />
paket add Lyo.Validation --version 1.0.1
#r "nuget: Lyo.Validation, 1.0.1"
#:package Lyo.Validation@1.0.1
#addin nuget:?package=Lyo.Validation&version=1.0.1
#tool nuget:?package=Lyo.Validation&version=1.0.1
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 + attributes —
ValidatorBuilder<T>/PropertyValidatorBuilder<T, TProperty>andAttributeValidator<T> - Schema documents —
ValidationSchemakeyed by name, optional target type,WhereClauseconstraints (In,NotIn,Regex, …) - Pluggable store —
IValidationSchemaStore(in-memory default; Postgres in a sibling package) - Shared error mapping —
WhereClauseExplainResult.ToErrorsin 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>andPropertyValidatorBuilder<T, TProperty>(includingIn/NotInfor scalar allow-lists). - Attribute-based validation through built-in attributes such as
Required,NotEmpty,NotWhiteSpace,Length,Regex,Email,Phone,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(PropertyName,AttemptedValue) attached to each failingError.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. RequiredAttribute → RequiredValue, EmailAddressAttribute → InvalidEmail,
RangeAttribute → OutOfRange); 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.Abstractions10.0.5— (direct, microsoft)System.ComponentModel.Annotations5.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.Cryptography2.6.2— (transitive, third-party, netstandard2.0)EasyCompressor2.1.0— (transitive, third-party)Konscious.Security.Cryptography.Argon21.3.1— (transitive, third-party)Microsoft.Bcl.AsyncInterfaces10.0.5— (transitive, microsoft, netstandard2.0)Microsoft.Extensions.Caching.Memory10.0.5— (transitive, microsoft)Microsoft.Extensions.Configuration.Binder10.0.5— (transitive, microsoft)Microsoft.Extensions.DependencyInjection10.0.5— (transitive, microsoft)Microsoft.Extensions.Logging.Abstractions10.0.5— (transitive, microsoft)Microsoft.Extensions.Options.ConfigurationExtensions10.0.5— (transitive, microsoft)System.Buffers4.6.1— (transitive, microsoft, netstandard2.0)System.IO.Hashing10.0.5— (transitive, microsoft, net10.0)System.Memory4.6.3— (transitive, microsoft, netstandard2.0)System.Text.Json10.0.5— (transitive, microsoft, netstandard2.0)System.Threading.Tasks.Extensions4.6.3— (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 (>= 1.0.1)
- Lyo.Exceptions (>= 1.0.1)
- Lyo.Query.Models (>= 1.0.1)
- Lyo.Result (>= 1.0.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.5)
- System.ComponentModel.Annotations (>= 5.0.0)
-
net10.0
- Lyo.Common (>= 1.0.1)
- Lyo.Exceptions (>= 1.0.1)
- Lyo.Query (>= 1.0.1)
- Lyo.Query.Models (>= 1.0.1)
- Lyo.Result (>= 1.0.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.5)
- System.ComponentModel.Annotations (>= 5.0.0)
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.