httpclient-factory

Configure IHttpClientFactory with named or keyed clients and resilience handlers.

1|Updated Apr 28, 2026
One-click install
npx skills add https://github.com/Trossitec/dotnet-claude-kit --skill httpclient-factory-trossitec
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: httpclient-factory
Source: https://github.com/Trossitec/dotnet-claude-kit/tree/main/skills/httpclient-factory
Command: npx skills add https://github.com/Trossitec/dotnet-claude-kit --skill httpclient-factory-trossitec

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill prevents performance and reliability issues caused by misusing HttpClient, such as socket exhaustion, missing retry/timeout/circuit breaker behavior, and inconsistent cross-cutting concerns across services.

Core Features & Use Cases

  • Safer client construction: Use IHttpClientFactory with named/typed/keyed clients to avoid per-request HttpClient creation and DNS/handler lifetime pitfalls.
  • Production-grade resilience: Add standardized retry, circuit breaker, timeouts, rate limiting, and optional hedging for external calls.
  • Clean cross-cutting integration: Register DelegatingHandlers for authentication, correlation IDs, and other pipeline concerns instead of scattering logic in service methods.
  • Practical .NET testing: Validate behavior using custom HttpMessageHandler/test handlers rather than brittle integration-only patterns.

Use case example: You are implementing a payments API integration in a .NET 10 service that must reliably handle transient failures; use keyed clients plus AddStandardResilienceHandler and a DelegatingHandler for auth, then unit test using a mock HttpMessageHandler.

Quick Start

Load the httpclient-factory skill and ask for a recommended .NET 10 registration snippet that uses keyed HttpClient plus standard resilience and an auth DelegatingHandler for your target external API.

Frequently Asked Questions about httpclient-factory

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I configure retry and circuit breaker behavior for .NET HttpClient?

Avoid socket exhaustion and DNS issues by using IHttpClientFactory to manage handler lifetimes instead of creating per-request HttpClient instances. The factory pools HttpMessageHandler instances and provides named, typed, or keyed clients for safe, reusable HTTP connections.

How do I add standard resilience handlers to keyed HttpClient in .NET?

Register a keyed HttpClient using AddHttpClient followed by AddAsKeyed, then apply AddStandardResilienceHandler to automatically enable retry, circuit breaking, timeouts, and optional hedging for that specific client's external HTTP integrations.

What is the best way to handle authentication headers consistently across HttpClient calls?

Register custom DelegatingHandlers with IHttpClientFactory to implement cross-cutting concerns like authentication, correlation IDs, and header propagation cleanly. This centralizes pipeline logic instead of scattering it across individual service methods.

How do I unit test HttpClient resilience logic without live external API calls?

Validate HttpClient behavior by injecting a custom HttpMessageHandler or test handler into your client configuration. This allows you to mock HTTP responses and test retry, circuit breaker, and DelegatingHandler logic deterministically without brittle integration tests.

Does IHttpClientFactory support keyed clients for dependency injection in .NET 10?

Yes, IHttpClientFactory supports keyed clients by registering them with AddHttpClient and AddAsKeyed. You can also use ConfigureHttpClientDefaults to apply standard resilience handlers and default configurations across multiple clients.