Robotico.Validation 1.0.3
Robotico.Validation
Result-based validation for .NET 8 and .NET 10. Defines IValidator<T> (Validate returns Result). Integrates with Robotico.Mediator's validation pipeline and Robotico.Result for validation errors.
Features
- IValidator<T> — Validate(instance) returns
Result; success orResult.ValidationError(...). - ValidationErrors — Helpers to build field-to-messages dictionaries:
ForField(name, message),ToResult(errors), and a ValidationErrorsBuilder to collect errors then callToResult(). - Works with Robotico.Mediator — Register validators per request type;
ValidationPipelineBehaviorruns them before handlers.
Installation
dotnet add package Robotico.Validation
Quick start
using Robotico.Validation;
using VoidResult = Robotico.Result.Result;
// Implement IValidator<T>
public sealed class CreateUserValidator : IValidator<CreateUserRequest>
{
public VoidResult Validate(CreateUserRequest request)
{
ValidationErrorsBuilder errors = ValidationErrors.CreateBuilder();
if (string.IsNullOrWhiteSpace(request.Name))
errors.Add("Name", "Name is required.");
if (request.Age < 0)
errors.Add("Age", "Age must be non-negative.");
return errors.ToResult();
}
}
// Or use ValidationErrors directly
VoidResult r = ValidationErrors.ForField("email", "Invalid format.");
Versioning
We follow Semantic Versioning. Version 1.0.0 is the first stable release. No breaking changes in minor/patch versions.
Documentation
See this README for usage and examples; the library follows the same quality bar as Robotico.Result.
Building and testing
From the repo root:
dotnet restore
dotnet build -c Release
dotnet test tests/Robotico.Validation.Tests/Robotico.Validation.Tests.csproj -c Release
With coverage:
dotnet test tests/Robotico.Validation.Tests/Robotico.Validation.Tests.csproj -c Release --collect:"XPlat Code Coverage"
Principal quality target: 90% line coverage. Optional CI gate (fail if below threshold) using the included runsettings:
dotnet test tests/Robotico.Validation.Tests/Robotico.Validation.Tests.csproj -c Release --collect:"XPlat Code Coverage" --settings tests/Robotico.Validation.Tests/coverlet.runsettings
Or with inline properties:
dotnet test tests/Robotico.Validation.Tests/Robotico.Validation.Tests.csproj -c Release --collect:"XPlat Code Coverage" /p:CollectCoverage=true /p:Threshold=90 /p:ThresholdType=line
Or open robotico-validation.slnx in your IDE and build from there.
Contributing
Run tests and coverage locally (see Building and testing). Open a pull request; ensure the build and 90% line-coverage gate pass. Code style is enforced via .editorconfig and analyzers.
License
See repository license file.
No packages depend on Robotico.Validation.