Skip to main content

RA.Utilities.Integrations.Extensions

The primary "glue" for your entire RA.Utilities.Integrations package. The classes in this namespace provide a set of extension methods that simplify and standardize the process of configuring, extending, and using HttpClient and its related components.

They follow the popular "fluent API" pattern, allowing developers to chain method calls together in a readable and discoverable way. Since v10.2.0 the methods are declared as C# 14 extension members, grouped into one class per receiver type.

Let's break down the purpose of each class:​

1. ServiceCollectionExtensions​

This is the most critical class in the namespace. It is the main entry point for setting up HttpClient integrations within the .NET dependency injection container.

  • AddHttpClientIntegration(...): This is the star of the show. It masterfully encapsulates the entire process of registering a typed HttpClient. It binds configuration, validates it on startup, and sets up the client's base address and timeout, all in a single line of code.
  • Handler registration: AddScopedHttpMessageHandler<T> and AddTransientHttpMessageHandler<T> register DelegatingHandlers in the DI container so they can be attached to typed clients.

2. HttpClientBuilderExtensions​

This class contains the pipeline methods that chain off AddHttpClientIntegration(...) and attach DelegatingHandlers to a specific typed client:

3. HttpRequestOptionsExtensions​

This class provides utility methods for working with HttpRequestOptions, which are typically used inside a DelegatingHandler.

  • GetClientIpAddress(): A useful utility for extracting the client's IP address from the request context, which is invaluable for logging and auditing purposes within a handler.