Exemple #1
0
        private async Task <EnrichedLoanRequest> CreditCheckLoanRequest(LoanRequest loanRequest, EnrichedLoanRequest enrichedLoanRequest)
        {
            using (var httpClient = new HttpClient(httpMessageHandlerFactory.Create(), true))
            {
                httpClient.BaseAddress = httpMessageHandlerFactory.BaseUri;

                var stringContent = new StringContent(JsonConvert.SerializeObject(loanRequest), Encoding.UTF8, "application/json");
                httpClient.DefaultRequestHeaders.Add("Request-Id", loanRequest.CitizenServiceNumber);
                logger.Information("Contacting credit check agency...");
                var response = await httpClient.PutAsync("api/creditcheck", stringContent);

                if (response.IsSuccessStatusCode)
                {
                    enrichedLoanRequest = await ProcessSuccessResponse(loanRequest, enrichedLoanRequest, response);
                }
                else
                {
                    logger.Error(
                        "Credit check service returned {code} {response} for {@request}",
                        response.StatusCode,
                        response.ReasonPhrase,
                        loanRequest);
                }
            }

            return(enrichedLoanRequest);
        }
    protected override Task <HttpResponseMessage> SendAsync(
        HttpRequestMessage request, CancellationToken cancellationToken)
    {
        HttpMessageHandler ephemeralHandler = factory.Create();

        ephemeralHandler.InnerHandler = this.InnerHandler;
        var invoker = new HttpMessageInvoker(ephemeralHandler);

        return(invoker.SendAsync(request, cancellationToken));
    }
 private async Task <LoanQuote> ExecuteWithResilience(LoanQuoteRequest loanQuoteRequest, IRegisteredBank bank)
 {
     return(await resiliencePolicy.Execute(async() =>
     {
         using (var httpClient = new HttpClient(httpMessageHandlerFactory.Create(), true))
         {
             return await SendLoanRequest(loanQuoteRequest, bank, httpClient);
         }
     }));
 }
        protected override HttpClient CreateHttpClient()
        {
            var handler = handlerFactory.Create(authHolder);

            return(new HttpClient(handler));
        }