From 3ba59940d04f4c19581e16414e461b0393b9997a Mon Sep 17 00:00:00 2001 From: Kevin BEAUGRAND Date: Tue, 16 Apr 2024 13:21:32 +0200 Subject: [PATCH] Fix #2942 - Add LoraWan service dependency before adding the http client. --- .../AzureServiceCollectionExtension.cs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/IoTHub.Portal.Infrastructure/Startup/AzureServiceCollectionExtension.cs b/src/IoTHub.Portal.Infrastructure/Startup/AzureServiceCollectionExtension.cs index 4022404fa..0f1b277d0 100644 --- a/src/IoTHub.Portal.Infrastructure/Startup/AzureServiceCollectionExtension.cs +++ b/src/IoTHub.Portal.Infrastructure/Startup/AzureServiceCollectionExtension.cs @@ -25,8 +25,6 @@ namespace IoTHub.Portal.Infrastructure.Startup using IoTHub.Portal.Models.v10.LoRaWAN; using Microsoft.Azure.Devices; using Microsoft.Azure.Devices.Provisioning.Service; - using Microsoft.EntityFrameworkCore; - using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using Polly; @@ -62,13 +60,13 @@ private static IServiceCollection AddLoRaWanSupport(this IServiceCollection serv return services; } - var transientHttpErrorPolicy = HttpPolicyExtensions - .HandleTransientHttpError() - .OrResult(c => c.StatusCode == HttpStatusCode.NotFound) - .WaitAndRetryAsync(3, _ => TimeSpan.FromMilliseconds(100)); + _ = services.AddTransient() + .AddTransient, LoRaWanDeviceService>(); - _ = services.AddHttpClient("RestClient") - .AddPolicyHandler(transientHttpErrorPolicy); + var transientHttpErrorPolicy = HttpPolicyExtensions + .HandleTransientHttpError() + .OrResult(c => c.StatusCode == HttpStatusCode.NotFound) + .WaitAndRetryAsync(3, _ => TimeSpan.FromMilliseconds(100)); _ = services.AddHttpClient((sp, client) => { @@ -109,9 +107,8 @@ private static IServiceCollection ConfigureMappers(this IServiceCollection servi private static IServiceCollection ConfigureServices(this IServiceCollection services) { - return services.AddTransient() - .AddTransient, DeviceService>() - .AddTransient, LoRaWanDeviceService>(); + return services + .AddTransient, DeviceService>(); } private static IServiceCollection ConfigureHealthCheck(this IServiceCollection services)