This solution demonstrates different approaches to configuring and using HttpClient in .NET 8 applications with custom HTTP message handlers (DelegatingHandlers).
The project showcases three different implementation patterns:
- manual configuration,
- Microsoft Dependency Injection,
- Autofac dependency injection.
- HTTP Message Handler Pipeline: Shows how to create and chain custom message handlers
- Dependency Injection Patterns: Compares different DI approaches for
HttpClientconfiguration
- Clone the repository
- Open the solution in Visual Studio 2022
- Start the server application (HttpClientDemo.WebApi)
- Run one of the client projects (Right click -> Debug -> Start New Instance)
Each client application targets https://localhost:7033/Dummy endpoint and demonstrates the same functionality using different configuration approaches.
- Type: Console Application (.NET 8)
- Purpose: Demonstrates manual
HttpClientconfiguration with message handlers, without dependency injection
- Type: Console Application (.NET 8)
- Purpose: Shows
HttpClientconfiguration using Microsoft's built-in dependency injection
- Type: Console Application (.NET 8)
- Purpose: Illustrates
HttpClientsetup with Autofac dependency injection container
- Type: Class Library (.NET 8)
- Purpose: Contains custom HTTP message handlers
- Components:
AuthenticationHandler: Adds Bearer token authentication to HTTP requestsDummy1Handler: Demonstration handler (part of handler pipeline)Dummy2Handler: Demonstration handler (part of handler pipeline)
- Type: Class Library (.NET 8)
- Purpose: Provides functionality to access the Web API.
- Type: Web App (.NET 8)
- Purpose: Provides a dummy Web API endpoint:
GET /Dummy