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 the raw response returned by the underlying service API. Mapped to IAddressValidationResponse instances by an IBatchApiResponseMapper<TResponse>.
- 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> used to forward a batch of
TRequestinstances to the underlying API and return the rawTApiResponse.batchResponseMapperIBatchApiResponseMapper<TApiResponse>An IBatchApiResponseMapper<TResponse> used to map individual items within a
TApiResponseto an IAddressValidationResponse.requestValidatorIValidator<TRequest>An IValidator<T> used to validate each
TRequestinstance before it is sent to the underlying API.batchResponseValidatorIBatchValidator<TApiResponse>An IBatchValidator<T> used to validate the
TApiResponsereturned by the underlying API, producing 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, in the order results should be returned in.
cancellationTokenCancellationTokenA 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
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.