liveBook · Manning

IHttpClientFactory

As explained in .NET MAUI in Action

IHttpClientFactory is a .NET dependency-injection service for creating configured HttpClient instances and managing their underlying handlers.

IHttpClientFactory is a dependency-injection service for creating named HttpClient instances with configured handler chains. Register each client with AddHttpClient, then request the required client by name where it is needed. section 8.3.3

A typical setup follows these steps:

  • Install or use Microsoft.Extensions.Http and register clients in the services collection with AddHttpClient. section 8.3.3
  • Give each client a unique name when clients serve different purposes. section 8.3.3
  • Register delegating handlers and attach them to the appropriate client’s handler chain. section 8.3.3
  • Inject IHttpClientFactory and call CreateClient with the required name. section 8.3.3

Authenticated API client

Register AuthHandler, then configure a client named AuthHandler.AUTHENTICATED_CLIENT with that handler. A BaseService can inject IHttpClientFactory and create the named client; requests made through it automatically receive the access-token header. section 8.3.3 section 8.5

How .NET MAUI in Action covers it

How deep it goes
Explains registration, naming, handler chaining, and resolution, but does not detail HttpClient internals.
Examples
Uses AuthHandler, AUTHENTICATED_CLIENT, AddApiClientServices, and BaseService as concrete configuration and consumption examples.
What it assumes
Assumes familiarity with C# classes and constructors while demonstrating dependency injection and services registration.
What you can do after
Operate/configure named HttpClient instances and attach reusable handlers for authenticated requests.
How it connects
Connects dependency injection, HttpClient, delegating handlers, services collections, and access-token headers.

Also explained in

Compare how 2 books explain IHttpClientFactory →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of .NET MAUI in Action. The section links point to the parts of the book it draws on.