Skip to content

Refactor to use IHttpClientFactory and implement IDisposable #4

@jmarbutt

Description

@jmarbutt

Problem

InngestClient owns a raw HttpClient, isn't IDisposable, and doesn't use IHttpClientFactory. This pattern has several issues:

  1. Socket exhaustion - Creating multiple clients risks exhausting sockets
  2. Configuration - Makes global configuration (timeouts, handlers, logging) harder
  3. Testing - Harder to mock HTTP calls in tests
  4. Best practices - Doesn't follow .NET HttpClient best practices

Location: Inngest/InngestClient.cs constructors

Suggested Solution

  1. Use IHttpClientFactory for HttpClient management
  2. Register a named/typed client in DI: services.AddHttpClient<InngestClient>()
  3. Implement IDisposable if the client owns any unmanaged resources
  4. Allow configuration via IHttpClientBuilder for policies, handlers, etc.

Benefits

  • Proper connection pooling and lifecycle management
  • Easier to add Polly policies for retries/circuit breakers
  • Better testability with MockHttpMessageHandler
  • Follows .NET best practices

Priority

Medium - important for production reliability.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions