diff --git a/src/SFA.DAS.CommitmentPayments.WebJob/Configuration/CommitmentPaymentsConfiguration.cs b/src/SFA.DAS.CommitmentPayments.WebJob/Configuration/CommitmentPaymentsConfiguration.cs index 0569f0b334..4d8ea79f90 100644 --- a/src/SFA.DAS.CommitmentPayments.WebJob/Configuration/CommitmentPaymentsConfiguration.cs +++ b/src/SFA.DAS.CommitmentPayments.WebJob/Configuration/CommitmentPaymentsConfiguration.cs @@ -1,5 +1,4 @@ using SFA.DAS.Commitments.Domain.Interfaces; -using SFA.DAS.Provider.Events.Api.Client; using SFA.DAS.Provider.Events.Api.Client.Configuration; namespace SFA.DAS.CommitmentPayments.WebJob.Configuration @@ -24,10 +23,10 @@ public class CommitmentPaymentsConfiguration : IConfiguration public class PaymentEventsApi : IPaymentsEventsApiConfiguration { public string ApiBaseUrl { get; set; } - public string Tenant { get; } - public string ClientId { get; } - public string ClientSecret { get; } - public string IdentifierUri { get; } + public string Tenant { get; set; } + public string ClientId { get; set; } + public string ClientSecret { get; set; } + public string IdentifierUri { get; set; } public string ClientToken { get; set; } } diff --git a/src/SFA.DAS.CommitmentPayments.WebJob/DependencyResolution/DefaultRegistry.cs b/src/SFA.DAS.CommitmentPayments.WebJob/DependencyResolution/DefaultRegistry.cs index 9c4299d65b..982e72352d 100644 --- a/src/SFA.DAS.CommitmentPayments.WebJob/DependencyResolution/DefaultRegistry.cs +++ b/src/SFA.DAS.CommitmentPayments.WebJob/DependencyResolution/DefaultRegistry.cs @@ -12,8 +12,6 @@ using SFA.DAS.Configuration; using SFA.DAS.Configuration.AzureTableStorage; using SFA.DAS.NLog.Logger; -using SFA.DAS.Provider.Events.Api.Client; -using SFA.DAS.Provider.Events.Api.Client.Configuration; using StructureMap; using IConfiguration = SFA.DAS.Commitments.Domain.Interfaces.IConfiguration; @@ -32,9 +30,6 @@ public DefaultRegistry() var config = GetConfiguration("SFA.DAS.CommitmentPayments"); - For().Use() - .Ctor().Is(config.PaymentEventsApi); - For().Use(config); For().Use(config); For().Use(x => new CurrentDateTime()); diff --git a/src/SFA.DAS.CommitmentPayments.WebJob/DependencyResolution/IoC.cs b/src/SFA.DAS.CommitmentPayments.WebJob/DependencyResolution/IoC.cs index db4c6fd5e4..e075abb21d 100644 --- a/src/SFA.DAS.CommitmentPayments.WebJob/DependencyResolution/IoC.cs +++ b/src/SFA.DAS.CommitmentPayments.WebJob/DependencyResolution/IoC.cs @@ -9,6 +9,7 @@ public static IContainer Initialize() return new Container(c => { c.AddRegistry(); + c.AddRegistry(); }); } } diff --git a/src/SFA.DAS.CommitmentPayments.WebJob/DependencyResolution/PaymentsRegistry.cs b/src/SFA.DAS.CommitmentPayments.WebJob/DependencyResolution/PaymentsRegistry.cs new file mode 100644 index 0000000000..59292d2ef9 --- /dev/null +++ b/src/SFA.DAS.CommitmentPayments.WebJob/DependencyResolution/PaymentsRegistry.cs @@ -0,0 +1,37 @@ +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().Use(c => c.GetInstance().PaymentEventsApi); + For().Use(c => c.GetInstance()); + For().Use().Ctor().Is(c => CreateClient(c)); + } + + private HttpClient CreateClient(IContext context) + { + var config = context.GetInstance().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; + } + } +} diff --git a/src/SFA.DAS.CommitmentPayments.WebJob/SFA.DAS.CommitmentPayments.WebJob.csproj b/src/SFA.DAS.CommitmentPayments.WebJob/SFA.DAS.CommitmentPayments.WebJob.csproj index 15ad074b92..5164e1d04c 100644 --- a/src/SFA.DAS.CommitmentPayments.WebJob/SFA.DAS.CommitmentPayments.WebJob.csproj +++ b/src/SFA.DAS.CommitmentPayments.WebJob/SFA.DAS.CommitmentPayments.WebJob.csproj @@ -260,6 +260,7 @@ + diff --git a/src/SFA.DAS.Commitments.AddEpaToApprenticeships.WebJob/Configuration/AddEpaToApprenticeshipsConfiguration.cs b/src/SFA.DAS.Commitments.AddEpaToApprenticeships.WebJob/Configuration/AddEpaToApprenticeshipsConfiguration.cs index bc2544e553..d20420dc10 100644 --- a/src/SFA.DAS.Commitments.AddEpaToApprenticeships.WebJob/Configuration/AddEpaToApprenticeshipsConfiguration.cs +++ b/src/SFA.DAS.Commitments.AddEpaToApprenticeships.WebJob/Configuration/AddEpaToApprenticeshipsConfiguration.cs @@ -1,5 +1,4 @@ using SFA.DAS.Commitments.Domain.Interfaces; -using SFA.DAS.Provider.Events.Api.Client; using SFA.DAS.Provider.Events.Api.Client.Configuration; namespace SFA.DAS.Commitments.AddEpaToApprenticeships.WebJob.Configuration @@ -23,10 +22,10 @@ public class AddEpaToApprenticeshipsConfiguration : IConfiguration // is this th public class PaymentEventsApi : IPaymentsEventsApiConfiguration { public string ApiBaseUrl { get; set; } - public string Tenant { get; } - public string ClientId { get; } - public string ClientSecret { get; } - public string IdentifierUri { get; } + public string Tenant { get; set; } + public string ClientId { get; set; } + public string ClientSecret { get; set; } + public string IdentifierUri { get; set; } public string ClientToken { get; set; } } diff --git a/src/SFA.DAS.Commitments.AddEpaToApprenticeships.WebJob/DependencyResolution/DefaultRegistry.cs b/src/SFA.DAS.Commitments.AddEpaToApprenticeships.WebJob/DependencyResolution/DefaultRegistry.cs index d20239dd8a..b4f9176b47 100644 --- a/src/SFA.DAS.Commitments.AddEpaToApprenticeships.WebJob/DependencyResolution/DefaultRegistry.cs +++ b/src/SFA.DAS.Commitments.AddEpaToApprenticeships.WebJob/DependencyResolution/DefaultRegistry.cs @@ -37,9 +37,6 @@ public DefaultRegistry() // ms fake would be preferable For().Use(x => new CurrentDateTime()); - For().Use() - .Ctor().Is(config.PaymentEventsApi); - For().Use() .Ctor().Is(config.AssessmentOrgsApiBaseUri); diff --git a/src/SFA.DAS.Commitments.AddEpaToApprenticeships.WebJob/DependencyResolution/IoC.cs b/src/SFA.DAS.Commitments.AddEpaToApprenticeships.WebJob/DependencyResolution/IoC.cs index 81735f7ec8..8d38c4e829 100644 --- a/src/SFA.DAS.Commitments.AddEpaToApprenticeships.WebJob/DependencyResolution/IoC.cs +++ b/src/SFA.DAS.Commitments.AddEpaToApprenticeships.WebJob/DependencyResolution/IoC.cs @@ -10,6 +10,7 @@ public static IContainer Initialize() var container = new Container(c => { c.AddRegistry(); + c.AddRegistry(); }); //Debug.WriteLine(container.WhatDidIScan()); diff --git a/src/SFA.DAS.Commitments.AddEpaToApprenticeships.WebJob/DependencyResolution/PaymentsRegistry.cs b/src/SFA.DAS.Commitments.AddEpaToApprenticeships.WebJob/DependencyResolution/PaymentsRegistry.cs new file mode 100644 index 0000000000..4083c53795 --- /dev/null +++ b/src/SFA.DAS.Commitments.AddEpaToApprenticeships.WebJob/DependencyResolution/PaymentsRegistry.cs @@ -0,0 +1,36 @@ +using System.Net.Http; +using SFA.DAS.Commitments.AddEpaToApprenticeships.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.Commitments.AddEpaToApprenticeships.WebJob.DependencyResolution +{ + internal class PaymentsRegistry : Registry + { + public PaymentsRegistry() + { + For().Use(c => c.GetInstance().PaymentEventsApi); + For().Use(c => c.GetInstance()); + For().Use().Ctor().Is(c => CreateClient(c)); + } + + private HttpClient CreateClient(IContext context) + { + var config = context.GetInstance().PaymentEventsApi; + + HttpClient httpClient = new HttpClientBuilder() + .WithBearerAuthorisationHeader(new AzureActiveDirectoryBearerTokenGenerator(config)) + .WithHandler(new RequestIdMessageRequestHandler()) + .WithHandler(new SessionIdMessageRequestHandler()) + .WithDefaultHeaders() + .Build(); + + + return httpClient; + } + } +} diff --git a/src/SFA.DAS.Commitments.AddEpaToApprenticeships.WebJob/SFA.DAS.Commitments.AddEpaToApprenticeships.WebJob.csproj b/src/SFA.DAS.Commitments.AddEpaToApprenticeships.WebJob/SFA.DAS.Commitments.AddEpaToApprenticeships.WebJob.csproj index 2f37fcdad7..42406c97cb 100644 --- a/src/SFA.DAS.Commitments.AddEpaToApprenticeships.WebJob/SFA.DAS.Commitments.AddEpaToApprenticeships.WebJob.csproj +++ b/src/SFA.DAS.Commitments.AddEpaToApprenticeships.WebJob/SFA.DAS.Commitments.AddEpaToApprenticeships.WebJob.csproj @@ -268,6 +268,7 @@ +