Atya.Errors.Validation
1.2.0
Prefix Reserved
dotnet add package Atya.Errors.Validation --version 1.2.0
NuGet\Install-Package Atya.Errors.Validation -Version 1.2.0
<PackageReference Include="Atya.Errors.Validation" Version="1.2.0" />
<PackageVersion Include="Atya.Errors.Validation" Version="1.2.0" />
<PackageReference Include="Atya.Errors.Validation" />
paket add Atya.Errors.Validation --version 1.2.0
#r "nuget: Atya.Errors.Validation, 1.2.0"
#:package Atya.Errors.Validation@1.2.0
#addin nuget:?package=Atya.Errors.Validation&version=1.2.0
#tool nuget:?package=Atya.Errors.Validation&version=1.2.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;
using Atya.Foundation.Results;
var validator = new CompositeValidator<CreateCustomerCommand>(
[
new NameRequiredValidator(),
new EmailFormatValidator(),
]);
var command = new CreateCustomerCommand("", "not-an-email");
var result = await validator.ValidateAsync(command);
Result commandResult = result.ToResult();
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.ValidationExtensions.ToErrorandToResultconvert validation failures intoAtya.Foundation.Resultserrors and results.
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.
Results
Use ToResult when validation errors are expected domain outcomes:
ValidationResult validation = await validator.ValidateAsync(command);
Result result = validation.ToResult();
Result<CreateCustomerCommand> typed = validation.ToResultWithValue(command);
Invalid validation results become ErrorKind.Validation failures. The parent
error contains one child Error in Details for each validation failure. Each
child uses the failure error code when present, otherwise
atya.errors.validation.failed; the child Message is the failure message and
Target is the property name.
The default result error code is atya.errors.validation.failed; pass explicit
error code and message values when an API owns a more specific 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)
- Atya.Foundation.Results (>= 1.1.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.2.0 | 152 | 7/10/2026 |
| 1.1.0 | 153 | 7/9/2026 |
| 1.0.1-oidc.20260621.1 | 78 | 6/21/2026 |
| 1.0.0 | 213 | 5/23/2026 |