﻿using System.Net.Http;
using SFA.DAS.CommitmentPayments.WebJob.Configuration;
using SFA.DAS.Http;
using SFA.DAS.Http.TokenGenerators;
using SFA.DAS.NLog.Logger.Web.MessageHandlers;
using SFA.DAS.Provider.Events.Api.Client;
using SFA.DAS.Provider.Events.Api.Client.Configuration;
using StructureMap;

namespace SFA.DAS.CommitmentPayments.WebJob.DependencyResolution
{
    internal class PaymentsRegistry : Registry
    {
        public PaymentsRegistry()
        {
            For<PaymentEventsApi>().Use(c => c.GetInstance<CommitmentPaymentsConfiguration>().PaymentEventsApi);
            For<IPaymentsEventsApiConfiguration>().Use(c => c.GetInstance<PaymentEventsApi>());
            For<IPaymentsEventsApiClient>().Use<PaymentsEventsApiClient>().Ctor<HttpClient>().Is(c => CreateClient(c));
        }

        private HttpClient CreateClient(IContext context)
        {
            var config = context.GetInstance<CommitmentPaymentsConfiguration>().PaymentEventsApi;

            HttpClient httpClient = new HttpClientBuilder()
                    .WithBearerAuthorisationHeader(new AzureActiveDirectoryBearerTokenGenerator(config))
                    .WithHandler(new RequestIdMessageRequestHandler())
                    .WithHandler(new SessionIdMessageRequestHandler())
                    .WithDefaultHeaders()
                    .Build();


            return httpClient;
        }
    }
}

﻿using System.Net.Http;
using SFA.DAS.CommitmentPayments.WebJob.Configuration;
using SFA.DAS.Http;
using SFA.DAS.Http.TokenGenerators;
using SFA.DAS.NLog.Logger.Web.MessageHandlers;
using SFA.DAS.Provider.Events.Api.Client;
using SFA.DAS.Provider.Events.Api.Client.Configuration;
using StructureMap;

namespace SFA.DAS.CommitmentPayments.WebJob.DependencyResolution
{
    internal class PaymentsRegistry : Registry
    {
        public PaymentsRegistry()
        {
            For<PaymentEventsApi>().Use(c => c.GetInstance<CommitmentPaymentsConfiguration>().PaymentEventsApi);
            For<IPaymentsEventsApiConfiguration>().Use(c => c.GetInstance<PaymentEventsApi>());
            For<IPaymentsEventsApiClient>().Use<PaymentsEventsApiClient>().Ctor<HttpClient>().Is(c => CreateClient(c));
        }

        private HttpClient CreateClient(IContext context)
        {
            var config = context.GetInstance<CommitmentPaymentsConfiguration>().PaymentEventsApi;

            HttpClient httpClient = new HttpClientBuilder()
                    .WithBearerAuthorisationHeader(new AzureActiveDirectoryBearerTokenGenerator(config))
                    .WithHandler(new RequestIdMessageRequestHandler())
                    .WithHandler(new SessionIdMessageRequestHandler())
                    .WithDefaultHeaders()
                    .Build();

            httpClient.DefaultRequestHeaders.Add("api-version", "2");

            return httpClient;
        }
    }
}

Add default request header to Payments API httpClient to look for version 2. Since removing the SecureHttpClient from PaymentEventsApiClient this header was lost. This only matters for data locks as that is the only controller action split by api version at present
Add default request header to Payments API httpClient to look for version 2. Since removing the SecureHttpClient from PaymentEventsApiClient this header was lost. This only matters for data locks as that is the only controller action split by api version at present
