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 API response the provider returns. An IApiResponseMapper<TResponse> maps it to an IAddressValidationResponse.
- 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> that sends
TRequestinstances to the provider and returns theTApiResponse.responseMapperIApiResponseMapper<TApiResponse>An IApiResponseMapper<TResponse> that maps
TApiResponseinstances to an IAddressValidationResponse.requestValidatorIValidator<TRequest>An IValidator<T> that validates
TRequestinstances before the service sends them to the provider.responseValidatorIValidator<TApiResponse>An IValidator<T> that validates
TApiResponseinstances the provider returns.
Exceptions
- ArgumentNullException
Thrown when
requestAdapter,responseMapper,requestValidator, orresponseValidatoris null.- InvalidImplementationException
Thrown when
requestValidatordoes not derive from AbstractAddressValidationRequestValidator<T>, or whenresponseValidatordoes not derive from AbstractValidator<T>.
Methods
ValidateAsync(TRequest, CancellationToken)
Validates the request instance asynchronously.
public Task<IAddressValidationResponse?> ValidateAsync(TRequest request, CancellationToken cancellationToken = default)
Parameters
requestTRequestThe
TRequestinstance to validate.cancellationTokenCancellationTokenA token that cancels the operation.
Returns
- Task<IAddressValidationResponse>
The validation result as an IAddressValidationResponse.
Remarks
The returned IAddressValidationResponse may be null if the provider returns no response. If the request or response fails validation, this method returns an EmptyAddressValidationResponse instead.