Questions tagged [ihttpclientfactory]

40 questions
8
votes
1 answer

Using named HttpClient from IHttpClientFactory in a custom client

I know I'll get crucified for asking this question that has been asked a million times before and I promise you that I've looked at most of those questions/answers but I'm still a bit stuck. This is a .NET Standard 2.0 class library supporting an…
Sam
  • 26,817
  • 58
  • 206
  • 383
5
votes
1 answer

Make ASP.NET core IHttpClientFactory throws when the requested named client is not defined

I'm working with ASP.NET core 3.1 and I'm writing a web api, starting from the Visual Studio 2019 built-in ASP.NET core web api template. One of my services has a dependency on the IHttpClientFactory service. I'm using the named client consumption…
4
votes
1 answer

How to use Polly and IHttpClientFactory per url

I am trying to find a way to use a HttpClient using IHttpClientFactory.CreateClient([name]) where [name] is an HttpClient that was configured using Polly in the Startup class using PolicyRegistry. I want that policy to apply for each of the urls…
Bercovici Adrian
  • 8,794
  • 17
  • 73
  • 152
4
votes
3 answers

HttpClient: This instance has already started one or more requests. Properties can only be modified before sending the first request

I have an ASP.NET MVC application which invokes an ASP.NET Web API REST Service each time a button is pressed in the UI. Each time this button is pressed below DumpWarehouseDataIntoFile method is executed. public class MyClass { private static…
Willy
  • 9,848
  • 22
  • 141
  • 284
3
votes
1 answer

.Net 7 slow response times from HTTPClient request every 6 minutes

We are experiencing an issue with HTTP requests where we are seeing that every 6 minutes a HTTP request is taking up to 162ms, on average these requests are taking 7ms. The metrics graph below shows a brief run of a K6 script calling our controller…
Alan Mulligan
  • 1,107
  • 2
  • 16
  • 35
3
votes
2 answers

HttpClient - Execute an async method before every call to SendAsync

I'm in an ASP.Net Core environment and want my classes to use a named HttpClient which they retrieve from an IHttpClientFactory. They need to add a Bearer token into the Authorization header. In order to do that, they need to make an async call…
3
votes
2 answers

Puzzled by the lifetime of the httpclient in the new ihttpfactory

Refacoring from the code where the norm was singleton httpclient to the new ihttpfactory I am so much puzzled by the lifetime of the httpClient: The typed client is registered as transient with DI. [Typed clients] This means all my former singleton…
rethabile
  • 3,029
  • 6
  • 34
  • 68
3
votes
1 answer

IHttpClientFactory for full framework (4.7) and IoC

I am trying to Register IHttpClientFactory in Full Framework 4.7 (not core). I am using IoC container (LightInject) Problem, that I do not have direct access to implementation of internal class…
2
votes
1 answer

What is the value in services.AddHttpClient()

I've just spent the last hour learning a ton about HttpClient (here and here and here and ...). And clearly I want to use IHttpClientFactory to get any HttpClient I need. But I have not seen a clear answer on one part. 95% of my HttpClient requests…
David Thielen
  • 28,723
  • 34
  • 119
  • 193
2
votes
1 answer

How to use IHttpClientFactory with .NET 4.8 without using DI from .NET Core/Standard

I've got a .NET 4.8 windows forms app which uses Autofac for DI. Currently, we're using a single HttpClient instance which is registered as a singleton: builder.Register(c => { var handler = c.Resolve(); var…
2
votes
1 answer

FileNotFoundException when starting Azure Function project which uses dependency injection of IHttpClientFactory locally

I am new to Azure Function and trying to create a test project of Azure Function which uses dependency injection of IHttpClientFactory. But I have been stuck with FileNotFoundException when starting the project locally from Visual Studio. The test…
emoacht
  • 2,764
  • 1
  • 13
  • 24
2
votes
1 answer

unable to make httpclientfactory working from a .net framework 4.7.2 winform project

i read about everything i could find about HttpClientFactory and after a few days struggling with this, i am about to give up, but taking a chance here in case anyone could help. I am just trying to implement HttpClientFactory in my .net 4.7.2…
2
votes
2 answers

How to use IHttpClientFactory with Autofac (using net framework)?

I am struggling to get the DI to work for IHttpClientFactory in autofac. Usually I work with the .net core dependency injection system and I do this: services.AddHttpClient(HttpClientConstants.HttpClientNameA, client => { …
Art
  • 163
  • 1
  • 8
1
vote
2 answers

Add dynamic parameter to DelegatingHandler used within the HttpClientFactory Service

I'm trying to use a IHttpClientFactory in my application in order to efficiently manage the HTTP Clients used throughout its lifecycle. Each of these clients need to have their bearer token set up depending on a specific Client ID which is only…
1
vote
1 answer

Why doesn't System.Net.Http.HttpClientFactory implement System.Net.Http.IHttpClientFactory?

I'm using .NET Framework 4.7.2 and am trying to use IHttpClientFactory to create HttpClient instances. I downloaded the Microsoft.Extensions.Http v7 NuGet Package and now have access to System.Net.Http.HttpClientFactory. Am I meant to use…
David Klempfner
  • 8,700
  • 20
  • 73
  • 153
1
2 3