AddHttpClient registers HttpClient with dependency injection and can associate configuration with a typed client. A typed client keeps remote-service HTTP logic behind a focused C# API. section 33.2.3
A typed-client registration provides several pieces at once:
- Registers HttpClient as a transient service backed by a pooled instance managed by IHttpClientFactory. section 33.2.3
- Registers the typed client as transient and configures the injected HttpClient through the AddHttpClient<T> callback. section 33.2.3
- Supports a typed client interface, such as IExchangeRatesClient, to make consuming code easier to test. section 33.2.3
- Can leave configuration in the client constructor instead, although central registration keeps endpoint settings visible in startup code. section 33.2.3
Register and consume a typed client
Register ExchangeRatesClient with AddHttpClient, set its BaseAddress and User-Agent, then inject it into an endpoint. The endpoint calls GetLatestRates without constructing requests or selecting a client by string name.
