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 API response the provider returns. An IBatchApiResponseMapper<TResponse> maps it to IAddressValidationResponse instances.

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> that sends a batch of TRequest instances to the provider and returns the TApiResponse.

batchResponseMapper IBatchApiResponseMapper<TApiResponse>

An IBatchApiResponseMapper<TResponse> that maps individual items within a TApiResponse to an IAddressValidationResponse.

requestValidator IValidator<TRequest>

An IValidator<T> that validates each TRequest instance before the service sends it to the provider.

batchResponseValidator IBatchValidator<TApiResponse>

An IBatchValidator<T> that validates the TApiResponse the provider returns. It produces 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, listed in the order the response must preserve.

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task<IReadOnlyList<IAddressValidationResponse>>

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

Remarks

The returned list has the same length and order as requests. An entry is an EmptyAddressValidationResponse when the corresponding request fails local validation, or when the provider cannot resolve that address. An entry is null only when the batch API call produces no response at all. This matches the "no response" semantics of ValidateAsync(TRequest, CancellationToken). A null entry can only occur at a position 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.