From 32e9a7799cd486e31d7d62f49b57521c82c3a4c1 Mon Sep 17 00:00:00 2001 From: tom-gough Date: Fri, 22 Nov 2024 12:15:57 +0000 Subject: [PATCH 1/2] FLP-1003 ICommitmentPermissionsApiClientFactory now resolves to the LocalDevApiClientFactory when running locally. --- ...ermissionsApiClientServiceRegistrations.cs | 21 ++++++++++++++++--- .../Startup.cs | 2 +- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/ServiceRegistrations/CommitmentPermissionsApiClientServiceRegistrations.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/ServiceRegistrations/CommitmentPermissionsApiClientServiceRegistrations.cs index 83a20aebc..25e81db11 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/ServiceRegistrations/CommitmentPermissionsApiClientServiceRegistrations.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/ServiceRegistrations/CommitmentPermissionsApiClientServiceRegistrations.cs @@ -1,15 +1,30 @@ -using SFA.DAS.EmployerCommitmentsV2.Client; +using Microsoft.Extensions.Configuration; +using SFA.DAS.CommitmentsV2.Api.Client.Configuration; +using SFA.DAS.EmployerCommitmentsV2.Client; +using SFA.DAS.EmployerCommitmentsV2.Web.Extensions; namespace SFA.DAS.EmployerCommitmentsV2.Web.ServiceRegistrations; public static class CommitmentPermissionsApiClientServiceRegistrations { - public static IServiceCollection AddCommitmentPermissionsApiClient(this IServiceCollection services) + public static IServiceCollection AddCommitmentPermissionsApiClient(this IServiceCollection services, IConfiguration configuration) { services.AddSingleton(); services.AddSingleton(provider => { - var factory = provider.GetService(); + ICommitmentPermissionsApiClientFactory factory; + + if (configuration.UseLocalRegistry()) + { + var config = provider.GetService(); + var loggerFactory = provider.GetService(); + factory = new LocalDevApiClientFactory(config, loggerFactory); + } + else + { + factory = provider.GetService(); + } + return factory.CreateClient(); }); diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web/Startup.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web/Startup.cs index 03969c8f0..d54317ee3 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web/Startup.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web/Startup.cs @@ -46,7 +46,7 @@ public void ConfigureServices(IServiceCollection services) .AddCommitmentsApiClient(_configuration) .AddAccountsApiClient(employerCommitmentsV2Configuration) .AddAuthorizationServices(_configuration) - .AddCommitmentPermissionsApiClient() + .AddCommitmentPermissionsApiClient(_configuration) .AddDasHealthChecks() .AddDasMaMenuConfiguration(_configuration) .AddDasMvc() From d1a30bfbf7ae02dffb2dfa494bf73f591a80c469 Mon Sep 17 00:00:00 2001 From: tom-gough Date: Fri, 22 Nov 2024 12:19:06 +0000 Subject: [PATCH 2/2] FLP-1003 test fix --- .../WhenAddingServicesToTheContainer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/WhenAddingServicesToTheContainer.cs b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/WhenAddingServicesToTheContainer.cs index 80d16a2a8..9ed5eb692 100644 --- a/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/WhenAddingServicesToTheContainer.cs +++ b/src/SFA.DAS.EmployerCommitmentsV2.Web.UnitTests/WhenAddingServicesToTheContainer.cs @@ -124,7 +124,7 @@ private static void SetupServiceCollection(IServiceCollection services) services.AddConfigurationOptions(configuration); services.AddDistributedMemoryCache(); services.AddModelMappings(); - services.AddCommitmentPermissionsApiClient(); + services.AddCommitmentPermissionsApiClient(configuration); services.AddApplicationServices(employerCommitmentsV2Configuration); services.AddModelMappings(); services.AddDasMvc();