Class AbstractBatchValidator<T>
- Namespace
- Visus.AddressValidation.Validation
- Assembly
- Visus.AddressValidation.dll
Base class for implementing a batch validator that produces one independent IValidationResult per item in a batch response.
public abstract class AbstractBatchValidator<T> : IBatchValidator<T> where T : class
Type Parameters
TThe object instance to be validated.
- Inheritance
-
AbstractBatchValidator<T>
- Implements
- Inherited Members
Methods
ExecuteAsync(T, IReadOnlyList<int>, CancellationToken)
Executes validation against the specified instance, producing one result per expected item.
public ValueTask<IReadOnlyList<IValidationResult>> ExecuteAsync(T instance, IReadOnlyList<int> requestIndexes, CancellationToken cancellationToken = default)
Parameters
instanceTThe instance to validate.
requestIndexesIReadOnlyList<int>The original, caller-facing index of each request sent to the provider, in the order sent. Its count is the number of items expected in the result. Use these values, instead of the positional loop index, when a validation message must reference an item's original position. Local validation may filter out some requests before the batch call, so the loop index does not match the original position.
cancellationTokenCancellationTokenA token that cancels the operation.
Returns
- ValueTask<IReadOnlyList<IValidationResult>>
A list of exactly
requestIndexes.CountIValidationResult objects, positionally aligned with the items sent to the provider.
PreValidateAsync(T, IReadOnlyList<int>, IReadOnlyList<ISet<ValidationState>>, CancellationToken)
Determines if validation should continue. Override it to add shared, batch-wide validation state that applies to every item before per-item validation runs.
protected virtual ValueTask<bool> PreValidateAsync(T instance, IReadOnlyList<int> requestIndexes, IReadOnlyList<ISet<ValidationState>> results, CancellationToken cancellationToken = default)
Parameters
instanceTThe instance to perform validation against.
requestIndexesIReadOnlyList<int>The original, caller-facing index of each request expected in the result.
resultsIReadOnlyList<ISet<ValidationState>>One ISet<T> of ValidationState objects per expected item, indexed positionally.
cancellationTokenCancellationTokenA token that cancels the operation.
Returns
ValidateAsync(T, IReadOnlyList<int>, IReadOnlyList<ISet<ValidationState>>, CancellationToken)
Validates the specified instance. It populates per-item validation state.
protected virtual ValueTask ValidateAsync(T instance, IReadOnlyList<int> requestIndexes, IReadOnlyList<ISet<ValidationState>> results, CancellationToken cancellationToken = default)
Parameters
instanceTThe object to perform validation against.
requestIndexesIReadOnlyList<int>The original, caller-facing index of each request expected in the result.
resultsIReadOnlyList<ISet<ValidationState>>One ISet<T> of ValidationState objects per expected item, indexed positionally.
cancellationTokenCancellationTokenA token that cancels the operation.
Returns
- ValueTask
A task that represents the asynchronous validation operation.