Class AbstractAddressValidationService<TRequest, TApiResponse>
- Namespace
- Visus.AddressValidation.Services
- Assembly
- Visus.AddressValidation.dll
Abstract base class for implementing an IAddressValidationService<TRequest>.
public abstract class AbstractAddressValidationService<TRequest, TApiResponse> : IAddressValidationService<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 an IAddressValidationResponse by an IApiResponseMapper<TResponse>.
- Inheritance
-
AbstractAddressValidationService<TRequest, TApiResponse>
- Implements
-
IAddressValidationService<TRequest>
- Inherited Members
Constructors
AbstractAddressValidationService(IApiRequestAdapter<TRequest, TApiResponse>, IApiResponseMapper<TApiResponse>, IValidator<TRequest>, IValidator<TApiResponse>)
Initializes a new instance of AbstractAddressValidationService<TRequest, TApiResponse>.
protected AbstractAddressValidationService(IApiRequestAdapter<TRequest, TApiResponse> requestAdapter, IApiResponseMapper<TApiResponse> responseMapper, IValidator<TRequest> requestValidator, IValidator<TApiResponse> responseValidator)
Parameters
requestAdapterIApiRequestAdapter<TRequest, TApiResponse>An IApiRequestAdapter<TRequest, TApiResponse> used to forward
TRequestinstances to the underlying API and return the rawTApiResponse.responseMapperIApiResponseMapper<TApiResponse>An IApiResponseMapper<TResponse> used to map
TApiResponseinstances to an IAddressValidationResponse.requestValidatorIValidator<TRequest>An IValidator<T> used to validate
TRequestinstances before they are sent to the underlying API.responseValidatorIValidator<TApiResponse>An IValidator<T> used to validate
TApiResponseinstances returned by the underlying API.
Exceptions
- ArgumentNullException
Thrown when
requestAdapter,responseMapper,requestValidator, orresponseValidatoris null.- InvalidImplementationException
Thrown when
requestValidatordoes not derive from AbstractAddressValidationRequestValidator<T>.
Methods
ValidateAsync(TRequest, CancellationToken)
Validates the request instance asynchronously.
public Task<IAddressValidationResponse?> ValidateAsync(TRequest request, CancellationToken cancellationToken = default)
Parameters
requestTRequestRequest to be validated represented as an instance of
TRequest.cancellationTokenCancellationTokenA cancellation token that can be used to cancel the work.
Returns
- Task<IAddressValidationResponse>
Result of the validation as represented by an instance of IAddressValidationResponse.
Remarks
The instance IAddressValidationResponse may be null if the request or validation failed.