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
TRequestThe type of the validation request. Must derive from AbstractAddressValidationRequest.
TApiResponseThe type of API response the provider returns. An IBatchApiResponseMapper<TResponse> maps it to IAddressValidationResponse instances.
- Inheritance
-
AbstractBatchAddressValidationService<TRequest, TApiResponse>
- Implements
-
IBatchAddressValidationService<TRequest>
- Inherited Members
Constructors
AbstractBatchAddressValidationService(IBatchApiRequestAdapter<TRequest, TApiResponse>, IBatchApiResponseMapper<TApiResponse>, IValidator<TRequest>, IBatchValidator<TApiResponse>)
Initializes a new instance of AbstractBatchAddressValidationService<TRequest, TApiResponse>.
protected AbstractBatchAddressValidationService(IBatchApiRequestAdapter<TRequest, TApiResponse> batchRequestAdapter, IBatchApiResponseMapper<TApiResponse> batchResponseMapper, IValidator<TRequest> requestValidator, IBatchValidator<TApiResponse> batchResponseValidator)
Parameters
batchRequestAdapterIBatchApiRequestAdapter<TRequest, TApiResponse>An IBatchApiRequestAdapter<TRequest, TApiResponse> that sends a batch of
TRequestinstances to the provider and returns theTApiResponse.batchResponseMapperIBatchApiResponseMapper<TApiResponse>An IBatchApiResponseMapper<TResponse> that maps individual items within a
TApiResponseto an IAddressValidationResponse.requestValidatorIValidator<TRequest>An IValidator<T> that validates each
TRequestinstance before the service sends it to the provider.batchResponseValidatorIBatchValidator<TApiResponse>An IBatchValidator<T> that validates the
TApiResponsethe provider returns. It produces one result per item sent.
Exceptions
- ArgumentNullException
Thrown when
batchRequestAdapter,batchResponseMapper,requestValidator, orbatchResponseValidatoris null.- InvalidImplementationException
Thrown when
requestValidatordoes not derive from AbstractAddressValidationRequestValidator<T>, or whenbatchResponseValidatordoes 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
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
requestsIReadOnlyList<TRequest>The addresses to validate, listed in the order the response must preserve.
cancellationTokenCancellationTokenA 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
requestsis null.- ArgumentException
Thrown synchronously when
requestscontains 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.