Extensions: Are HttpMessageHandlers scoped per Typed HttpClient or a the internal HttpClient?

Created on 4 Oct 2018  路  3Comments  路  Source: dotnet/extensions

I have the following scenario:

  • I have two different typed HttpClients
  • I have a customer HttpMessageHandler called MyCustomHandler
  • I Configure them like this:
services
     .AddHttpClient<TeamCity.Client>()
     .AddHttpMessageHandler(() => new MyCustomHandler())

services
     .AddHttpClient<GitHub.Client>()
     .AddHttpMessageHandler(() => new MyCustomHandler())
  • I notice that the handler attached to TeamCity.Client is actually intercepting requests made through GitHub.Client ?

I don't understand what is happening here?

  1. Are those handlers attached and registered by type and thus they monitor every outgoing request even if it is not made through their typed http client?
  2. If the answer to previous question is yes, then why you can ONLY configure handlers when you register (AddHttpClient<>()) named or typed clients?
3 - Done area-httpclientfactory bug

Most helpful comment

What's going on here is that these clients end up with the same name because the the class names are the same Client. This isn't great 馃槩 I'm going to see if I can make this report an exception instead, because this is confusing an unintended.

You can also pass a name when adding a typed client with AddHttpClient, which should help keep them separated.

All 3 comments

What's going on here is that these clients end up with the same name because the the class names are the same Client. This isn't great 馃槩 I'm going to see if I can make this report an exception instead, because this is confusing an unintended.

You can also pass a name when adding a typed client with AddHttpClient, which should help keep them separated.

馃憤

Was this page helpful?
0 / 5 - 0 ratings