Table of Contents

Class AbstractBatchAddressValidationService<TRequest, TApiResponse>

Namespace
Visus.AddressValidation.Services
Assembly
Visus.AddressValidation.dll

Abstract base class for implementing an IBatchAddressValidationService<TRequest> for a provider whose API natively supports validating multiple addresses in a single call.

public abstract class AbstractBatchAddressValidationService<TRequest, TApiResponse> : IBatchAddressValidationService<TRequest> where TRequest : AbstractAddressValidationRequest where TApiResponse : class

Type Parameters

TRequest

The type of the validation request. Must derive from AbstractAddressValidationRequest.

TApiResponse

The type of the raw response returned by the underlying service API. Mapped to IAddressValidationResponse instances by an IBatchApiResponseMapper<TResponse>.

Inheritance
AbstractBatchAddressValidationService<TRequest, TApiResponse>
Implements
Inherited Members

Constructors

AbstractBatchAddressValidationService(IBatchApiRequestAdapter<TRequest, TApiResponse>, IBatchApiResponseMapper<TApiResponse>, IValidator<TRequest>, IBatchValidator<TApiResponse>)

protected AbstractBatchAddressValidationService(IBatchApiRequestAdapter<TRequest, TApiResponse> batchRequestAdapter, IBatchApiResponseMapper<TApiResponse> batchResponseMapper, IValidator<TRequest> requestValidator, IBatchValidator<TApiResponse> batchResponseValidator)

Parameters

batchRequestAdapter IBatchApiRequestAdapter<TRequest, TApiResponse>

An IBatchApiRequestAdapter<TRequest, TApiResponse> used to forward a batch of TRequest instances to the underlying API and return the raw TApiResponse.

batchResponseMapper IBatchApiResponseMapper<TApiResponse>

An IBatchApiResponseMapper<TResponse> used to map individual items within a TApiResponse to an IAddressValidationResponse.

requestValidator IValidator<TRequest>

An IValidator<T> used to validate each TRequest instance before it is sent to the underlying API.

batchResponseValidator IBatchValidator<TApiResponse>

An IBatchValidator<T> used to validate the TApiResponse returned by the underlying API, producing one result per item sent.

Exceptions

ArgumentNullException

Thrown when batchRequestAdapter, batchResponseMapper, requestValidator, or batchResponseValidator is null.

InvalidImplementationException

Thrown when requestValidator does not derive from AbstractAddressValidationRequestValidator<T>, or when batchResponseValidator does not derive from AbstractBatchValidator<T> .

Properties

MaxBatchSize

Gets the maximum number of requests this provider's API accepts in a single batch call.

protected abstract int MaxBatchSize { get; }

Property Value

int

Methods

ValidateManyAsync(IReadOnlyList<TRequest>, CancellationToken)

Validates the specified requests asynchronously as a single batch call.

public Task<IReadOnlyList<IAddressValidationResponse?>> ValidateManyAsync(IReadOnlyList<TRequest> requests, CancellationToken cancellationToken = default)

Parameters

requests IReadOnlyList<TRequest>

The addresses to validate, in the order results should be returned in.

cancellationToken CancellationToken

A cancellation token that can be used to cancel the work.

Returns

Task<IReadOnlyList<IAddressValidationResponse>>

A task producing a list of IAddressValidationResponse (or null), positionally aligned with requests.

Remarks

The returned list always has the same length and the same order as requests. An entry is an EmptyAddressValidationResponse when the corresponding request failed local validation, or when the provider could not resolve that specific address. An entry is null only when the entire underlying API call for the batch produced no response at all (mirroring the "no response" semantics of ValidateAsync(TRequest, CancellationToken)); this can only ever apply to positions that held a locally-valid request.

Exceptions

ArgumentNullException

Thrown when requests is null.

ArgumentException

Thrown synchronously when requests contains more items than the provider's maximum supported batch size.

InvalidImplementationException

Thrown when the registered batch response validator returns a different number of results than the number of items sent to the provider.