httpclient-factory

Standardize IHttpClientFactory client registration with resilience handlers in .NET 10.

224|87|Updated Dec 15, 2018
One-click install
npx skills add https://github.com/Resgrid/Core --skill httpclient-factory-resgrid
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: httpclient-factory
Source: https://github.com/Resgrid/Core/tree/main/.opencode/skills/httpclient-factory
Command: npx skills add https://github.com/Resgrid/Core --skill httpclient-factory-resgrid

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill prevents production HTTP issues like socket exhaustion, brittle configuration, and unreliable outbound calls by standardizing how IHttpClientFactory-based clients are created and used.

Core Features & Use Cases

  • Safe client creation: Enforces factory-managed HttpClient lifetimes to avoid per-request instantiation and DNS-related problems.
  • Named/Keyed client patterns: Guides selection of named and keyed clients (including .NET 10 keyed registration) for clear configuration and correct lifetimes.
  • Resilience by default: Shows how to apply Microsoft.Extensions.Http.Resilience with retries, circuit breakers, and timeouts, plus when to disable retries for unsafe methods.
  • DelegatingHandler pipeline: Centralizes cross-cutting concerns such as auth token injection and correlation ID propagation so services stay clean.
  • Testing-friendly HTTP: Demonstrates mock HttpMessageHandler patterns for deterministic integration and unit tests.

Quick Start

Register an IHttpClientFactory client for your external API and attach AddStandardResilienceHandler() so every outbound call gets consistent retry, timeout, and circuit breaker behavior.

Frequently Asked Questions about httpclient-factory

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

FAQPage Schema
How do I prevent socket exhaustion when creating HttpClient instances in .NET 10?

To prevent socket exhaustion in .NET 10, use IHttpClientFactory to manage HttpClient lifetimes rather than instantiating them per-request. This standardizes client creation and eliminates unsafe instantiation patterns that cause socket depletion.

How do I configure retries and circuit breakers for outbound HTTP calls in .NET?

You configure retries and circuit breakers for outbound HTTP calls by registering clients with AddHttpClient and attaching AddStandardResilienceHandler(). This applies consistent resilience policies to every outbound request, with options to disable retries for unsafe HTTP methods.

What is the difference between named and keyed clients in IHttpClientFactory?

Named and keyed clients in IHttpClientFactory provide clear configuration and correct lifetime management for distinct external APIs. .NET 10 introduces keyed client registration, allowing precise selection and management of multiple differently-configured HTTP clients within your application.

Can I use DelegatingHandlers to inject auth tokens and correlation IDs in .NET HTTP clients?

Yes, you can use a DelegatingHandler pipeline to centralize cross-cutting concerns like auth token injection and correlation ID propagation in .NET HTTP clients. This handler-pipeline pattern keeps your core services clean and separates external HTTP behavior from business logic.

How do I unit test HTTP clients that use IHttpClientFactory and resilience handlers?

You unit test HTTP clients using IHttpClientFactory by implementing mock HttpMessageHandler patterns. This provides deterministic responses for integration and unit tests, allowing you to validate outbound HTTP behavior without making actual network calls.

When should I disable retry policies for HTTP requests using Microsoft.Extensions.Http.Resilience?

You should disable retry policies for unsafe HTTP methods like POST when using Microsoft.Extensions.Http.Resilience to prevent duplicate side effects. Configure AddStandardResilienceHandler selectively to ensure retries only apply to safe, idempotent outbound operations.