Qowaiv.Validation.Abstractions
11.0.0
Prefix Reserved
dotnet add package Qowaiv.Validation.Abstractions --version 11.0.0
NuGet\Install-Package Qowaiv.Validation.Abstractions -Version 11.0.0
<PackageReference Include="Qowaiv.Validation.Abstractions" Version="11.0.0" />
<PackageVersion Include="Qowaiv.Validation.Abstractions" Version="11.0.0" />
<PackageReference Include="Qowaiv.Validation.Abstractions" />
paket add Qowaiv.Validation.Abstractions --version 11.0.0
#r "nuget: Qowaiv.Validation.Abstractions, 11.0.0"
#:package Qowaiv.Validation.Abstractions@11.0.0
#addin nuget:?package=Qowaiv.Validation.Abstractions&version=11.0.0
#tool nuget:?package=Qowaiv.Validation.Abstractions&version=11.0.0
Qowaiv Validation Abstractions
Core abstractions for model validation. Provides a vendor-lock-in-free
IValidator<TModel> / Result<TModel> abstraction that DataAnnotations,
FluentValidation, and XML validators all implement.
IValidator<TModel>
The main interface. Validates a model and returns the validation result.
public interface IValidator<TModel>
{
Result<TModel> Validate(TModel model);
}
Validator.Composite
To combine validators you can create a composite validator:
var composite = Validator.Composite(new SpecialValidator(), new CustomValidator());
Validator.Empty
To create a validator that always returns a valid result:
IValidator<MyModel> validator = Validator.Empty<MyModel>();
Result<MyModel> result = validator.Validate(model); // always valid
Result and Result<TModel>
A validation result containing messages. Created only via factory methods.
Result<DataType> ok = Result.OK;
Result<DataType> withValue = Result.For(value);
Result<DataType> withErrors = Result.For(value, ValidationMessage.Error("Bad"));
Result<DataType> nullResult = Result.Null<DataType>();
Result<DataType> withMessages = Result.WithMessages<DataType>(ValidationMessage.Warn("Check"));
AsyncResult<DataType> asyncValue = Result.Async(value);
The Async<T>() factory creates an AsyncResult<T>.
An existing Result<TModel> can be turned into an AsyncResult<TModel> with
Async() (the older AsTask() is obsolete).
Properties
Messages— all validation messagesIsValid—truewhen there are no error-severity messagesErrors/Warnings/Infos— filtered views by severity
Value access
The generic Result<TModel> wraps a Value that is only accessible when
valid. Accessing Value on an invalid result throws InvalidModel.
Result<MyModel> result = Validate(model);
if (result.IsValid)
{
MyModel value = result.Value; // safe
}
Throw if invalid
When you want to fail fast:
result.ThrowIfInvalid(); // throws InvalidModel if invalid
Implicit and explicit casts
// Implicit: valid values auto-wrap into Result<T>
Result<MyModel> implicit = validModel;
// Explicit: extracts the value, throws if invalid
MyModel explicit = (MyModel)result;
// Cast: changes the wrapped type (must be a subclass)
Result<DerivedModel> casted = result.Cast<DerivedModel>();
Result composition
Act
Chain multiple validation/transformation steps. Subsequent actions execute only while the result is valid, and messages accumulate:
Result<DataType> result = GetModel()
.Act(m => ValidateName(m))
.Act(m => ValidateAge(m));
ActAsync
Async versions for all Act overloads. They return an AsyncResult<TModel>,
which can be awaited to obtain the resulting Result<TModel>:
AsyncResult<DataType> async = Result.For(model)
.ActAsync(m => FetchDetailsAsync(m))
.ActAsync(m => SaveAsync(m));
Result<DataType> result = await async;
The invoked actions may return Result<TOut>, AsyncResult<TOut>, or
AsyncResult (see AsyncResult<TModel>).
Act with a transform
An action can also return a plain value, transforming the model (or a related
value) without producing messages. A null transform result makes the result
throw NoValue:
Result<Name> name = GetPerson()
.Act(p => p.Name); // TOut is Name
Pipe operator
The | operator provides an alternative syntax for Act:
Result<DataType> result = GetModel()
| ValidateName
| ValidateAge;
It also supports a pure TModel-to-TModel transform on both Result<TModel>
and AsyncResult<TModel>:
Result<DataType> result = GetModel() | Normalize;
Act with context update
For mutable or immutable shared context patterns:
// Mutable update
Result<Context> ctx = NewContext()
.Act(c => Service.GetValue(), (c, value) => c.Value = value);
// Immutable update
Result<Context> ctx = NewContext()
.Act(c => Service.GetValue(), (c, value) => c.Update(value));
AsyncResult<TModel>
AsyncResult<TModel> represents an operation that produces a Result<TModel>
at some time in the future. It is a lightweight readonly struct that wraps a
Task<Result<TModel>>, is awaitable, and exposes the same composition
(ActAsync and |) as Result<TModel>.
Creating
An AsyncResult<TModel> is created from a Result<TModel> via Async(), via
the Result.Async<T>() factory, or implicitly from a Task<Result<TModel>>:
AsyncResult<MyModel> fromResult = Result.For(model).Async();
AsyncResult<MyModel> fromFactory = Result.Async(model);
AsyncResult<MyModel> fromFactoryWithMessages = Result.Async(model, ValidationMessage.Warn("Check"));
AsyncResult<MyModel> fromTask = Task.FromResult(Result.For(model));
Awaiting
Because AsyncResult<TModel> is awaitable, awaiting it yields the underlying
Result<TModel>. It also mirrors the underlying task via IsCompleted and
IsCanceled:
Result<MyModel> result = await Result.Async(model);
Composition
ActAsync runs the next step only while the result is valid and merges the
messages, exactly like Act on Result<TModel>:
Result<DataType> result = await Result.Async(model)
.ActAsync(m => FetchDetailsAsync(m))
.ActAsync(m => SaveAsync(m));
The | operator works on AsyncResult<TModel> as well:
Result<DataType> result = await (Result.Async(model)
| ValidateName
| SaveAsync);
IValidationMessage
The common interface for all validation messages.
public interface IValidationMessage
{
ValidationSeverity Severity { get; }
string? PropertyName { get; }
string? Message { get; }
}
ValidationMessage
A concrete, sealed implementation with factory methods:
IValidationMessage error = ValidationMessage.Error("Name is required", "Name");
IValidationMessage warn = ValidationMessage.Warn("Deprecated field");
IValidationMessage info = ValidationMessage.Info("Auto-corrected");
IValidationMessage none = ValidationMessage.None; // null
ValidationSeverity
public enum ValidationSeverity
{
Info = 0,
Warning = 1,
Error = 2,
}
| 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. net11.0 is compatible. |
| .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
- System.Memory (>= 4.6.3)
- System.Runtime.CompilerServices.Unsafe (>= 6.1.2)
-
net10.0
- No dependencies.
-
net11.0
- No dependencies.
NuGet packages (8)
Showing the top 5 NuGet packages that depend on Qowaiv.Validation.Abstractions:
| Package | Downloads |
|---|---|
|
Qowaiv.Validation.DataAnnotations
Qowaiv Validation supports a generic interface for (domain) model validation. |
|
|
Qowaiv.Validation.Messages
Qowaiv Validation supports a generic interface for (domain) model validation. |
|
|
Qowaiv.Validation.Fluent
Qowaiv Validation supports a generic interface for (domain) model validation. |
|
|
Qowaiv.DomainModel
Qowaiv implements common, universal domain objects. These types form the base of your domain model. |
|
|
Qowaiv.Validation.Guarding
Qowaiv Validation supports a generic interface for (domain) model validation. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 11.0.0 | 86 | 11/26/2026 |
| 11.0.0-rc.1 | 141 | 11/20/2026 |
| 2.1.0 | 70,719 | 5/21/2026 |
| 2.0.0 | 43,111 | 1/19/2026 |
| 1.0.0 | 79,478 | 11/19/2024 |
| 0.3.0 | 87,192 | 3/7/2023 |
| 0.2.1 | 45,479 | 4/13/2022 |
| 0.1.3 | 4,487 | 3/24/2022 |
| 0.1.2 | 20,874 | 10/7/2021 |
| 0.1.1 | 17,760 | 9/10/2021 |
| 0.1.0 | 13,475 | 8/31/2021 |
| 0.0.5 | 1,168 | 8/19/2021 |
| 0.0.4 | 18,295 | 7/30/2020 |
| 0.0.3 | 9,822 | 11/25/2019 |
| 0.0.2 | 4,325 | 11/1/2019 |
| 0.0.1 | 3,014 | 7/30/2019 |
v11.0.0
- Add .NET 11.0 target.
- Drop .NET 8.0 targets (BREAKING)
- InvalidModelException renamed to InvalidModel. (BREAKING)
- Rely on built-in collection merging isntead of home-brew collection.
- Prevent creation of a valid Result<T> without setting T when struct. (BUG)
- ValidationMessages is an immutable collection, and type of Messages in Result. (BREAKING)
- Act(Async)(Func<TModel, TOut>) to simplify applying transforms.
- Validator.Composite<TModel>() creates a composite Ivalidator<<TModel>.
- IHttpStatusMessage to bind an IValidationMessage to an HTTP status.
v2.1.0
- Add notnull constraint to Result.For<T>().
v2.0.0
- Add Result.ThrowIfInvalid().
- Add .NET 10.0 target.
- Drop .NET9.0 targets. (BREAKING)
v1.0.0
- Add .NET 9.0 target.
- Drop .NET 5.0, NET6.0, NET7.0 targets. (BREAKING)
- Drop public Diagnostics.Contracts. (BREAKING)
- Drop binary serialization on exceptions. (BREAKING)
v0.3.0
- Add Result<T>.Cast<TOut>(). #61
- Support .NET 7.0. #62
v0.2.1
- Nullable anotations. #48
v0.1.3
- Result.Null() also for (nullable) structs. #46
v0.1.2
- Dealing with Result.Null() values internally should not throw. #42
v0.1.1
- Decorate pure methods with attribute. #38
v0.1.0
- ContinueOnCapturedContext is configurable. #35
- Introduction of Result.Null<T>(). #34
- Disallow Result<T>.For(null). #34
- Act() and ActAsync() are also executed for null values. #34
- Result.OK is static readonly field (was static property). #32
- Improvements on InvalidModelException. #31
v0.0.5
- Act() methods on context. #29
- AsTask() method for Result<T>. #28
v0.0.4
- Act() methods have pipe notation alternatives.