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 configure and chained message handlers
- Dependency Injection Patterns: Compares different DI approaches for
HttpClientconfiguration (including message handlers)
- Clone the repository
- Open the solution in Visual Studio
- Start the server application (WebApi)
- Run one of the client projects (Right click -> Debug -> Start New Instance)
Each client application is:
- adding two custom
DelegatingHandlers to theHttpClientinstance - calls the
https://localhost:7033/Demoendpoint.
- 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: Provides a class that calls the server API.
- Components:
Dummy1Handler: 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