Atya.Errors.Validation
1.0.0
dotnet add package Atya.Errors.Validation --version 1.0.0
NuGet\Install-Package Atya.Errors.Validation -Version 1.0.0
<PackageReference Include="Atya.Errors.Validation" Version="1.0.0" />
<PackageVersion Include="Atya.Errors.Validation" Version="1.0.0" />
<PackageReference Include="Atya.Errors.Validation" />
paket add Atya.Errors.Validation --version 1.0.0
#r "nuget: Atya.Errors.Validation, 1.0.0"
#:package Atya.Errors.Validation@1.0.0
#addin nuget:?package=Atya.Errors.Validation&version=1.0.0
#tool nuget:?package=Atya.Errors.Validation&version=1.0.0
Validation
Transport-agnostic validation abstractions, models, helpers, and composite validators for the Atya Errors group.
This package provides small validation building blocks for domain, application, worker, and API layers without any transport-specific concepts. It intentionally does not include a rules DSL, reflection-based validation, ASP.NET integration, or localization.
Install
dotnet add package Atya.Errors.Validation
Supported framework
Atya.Errors.Validation targets net10.0.
Quick start
using Atya.Errors.Validation.Abstractions;
using Atya.Errors.Validation.Extensions;
using Atya.Errors.Validation.Models;
using Atya.Errors.Validation.Validators;
var validator = new CompositeValidator<CreateCustomerCommand>(
[
new NameRequiredValidator(),
new EmailFormatValidator(),
]);
var command = new CreateCustomerCommand("", "not-an-email");
var result = await validator.ValidateAsync(command);
if (!result.IsValid)
{
foreach (var error in result.Errors)
{
Console.WriteLine($"{error.PropertyName}: {error.Message}");
}
}
sealed record CreateCustomerCommand(string Name, string Email);
sealed class NameRequiredValidator : IValidator<CreateCustomerCommand>
{
public ValueTask<ValidationResult> ValidateAsync(
CreateCustomerCommand instance,
CancellationToken cancellationToken = default)
{
_ = cancellationToken;
return string.IsNullOrWhiteSpace(instance.Name)
? ValueTask.FromResult(ValidationResult.FromFailure(
ValidationFailureFactory.Required(nameof(instance.Name), instance.Name)))
: ValueTask.FromResult(ValidationResult.Success);
}
}
sealed class EmailFormatValidator : IValidator<CreateCustomerCommand>
{
public ValueTask<ValidationResult> ValidateAsync(
CreateCustomerCommand instance,
CancellationToken cancellationToken = default)
{
_ = cancellationToken;
return instance.Email.Contains('@', StringComparison.Ordinal)
? ValueTask.FromResult(ValidationResult.Success)
: ValueTask.FromResult(ValidationResult.FromFailure(
ValidationFailureFactory.Invalid(
nameof(instance.Email),
"Email must contain '@'.",
instance.Email)));
}
}
Core APIs
IValidator<T>defines the async validation contract.ValidationFailureis an immutable value object for one property or logical field failure.ValidationResultrepresents success or one or more failures.ValidationFailureFactorycreates standard Atya validation failures.ValidatorExtensions.ValidateAllAsyncexecutes validators in order and combines failures.ValidatorExtensions.ValidateAndThrowAsyncvalidates with one validator and throws on failure.CompositeValidator<T>composes several validators behind oneIValidator<T>.ValidationExtensions.ThrowIfInvalidandToValidationExceptionconvert failures intoAtya.Errors.Exceptions.ValidationException.
Behavior
ValidationFailuretrimsPropertyName,Message, and non-emptyErrorCodevalues.- Empty or whitespace
PropertyNameandMessagevalues throwArgumentException. - Empty failure collections produce
ValidationResult.Success. - Result and failure collections are copied before storage, so callers cannot mutate a result through the original input collection.
- Composite and extension-based validation runs validators sequentially in the order provided.
- Cancellation is checked before each validator and the same token is passed to validators.
- Validators must return a non-null
ValidationResult; a null result throwsArgumentNullException.
Exceptions
Use ThrowIfInvalid when validation errors should become an Atya validation exception:
await validator.ValidateAndThrowAsync(command);
The default exception message is Validation failed. and the default error code
is validation.failed. Provide explicit values when those should be part of a
public API contract.
Versioning and support
Stable releases use SemVer and are produced from vMAJOR.MINOR.PATCH tags.
Breaking API changes should wait for the next major version. Bug fixes and new
non-breaking helpers can be released in patch or minor versions as appropriate.
| Product | Versions 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. |
-
net10.0
- Atya.Errors.Exceptions (>= 1.0.0)
- Atya.Foundation.Guards (>= 1.0.0)
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 | 94 | 5/23/2026 |