From 197653c1c7eb12812f49db7ae957d2fbdbee661e Mon Sep 17 00:00:00 2001 From: Artur Date: Thu, 18 Jan 2024 02:18:51 +0100 Subject: [PATCH 1/2] add throw error --- src/Core/Extensions/Http.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Core/Extensions/Http.cs b/src/Core/Extensions/Http.cs index 439f1ff..9ce7725 100644 --- a/src/Core/Extensions/Http.cs +++ b/src/Core/Extensions/Http.cs @@ -23,6 +23,10 @@ internal static async Task ExecuteHttpProxyOperationAsync(this HttpContext conte var httpClient = context.RequestServices .GetService() .CreateClient(options?.HttpClientName ?? Helpers.HttpProxyClientName); + var clientFactory = context.RequestServices.GetService() + ?? throw new InvalidOperationException("IHttpClientFactory not registered. You need to add builder.Services.AddHttpClient(); during startup"); + + var httpClient = clientFactory.CreateClient(options?.HttpClientName ?? Helpers.HttpProxyClientName); // If `true`, this proxy call has been intercepted. if(options?.Intercept != null && await options.Intercept(context).ConfigureAwait(false)) From e9393fd45691efeb7c50443bdf7da15acc640b40 Mon Sep 17 00:00:00 2001 From: Artur Date: Thu, 18 Jan 2024 13:39:45 +0100 Subject: [PATCH 2/2] Fix --- src/Core/Extensions/Http.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Core/Extensions/Http.cs b/src/Core/Extensions/Http.cs index 9ce7725..4a17b71 100644 --- a/src/Core/Extensions/Http.cs +++ b/src/Core/Extensions/Http.cs @@ -20,9 +20,6 @@ internal static async Task ExecuteHttpProxyOperationAsync(this HttpContext conte try { - var httpClient = context.RequestServices - .GetService() - .CreateClient(options?.HttpClientName ?? Helpers.HttpProxyClientName); var clientFactory = context.RequestServices.GetService() ?? throw new InvalidOperationException("IHttpClientFactory not registered. You need to add builder.Services.AddHttpClient(); during startup");