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 typedHttpClient. 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>andAddTransientHttpMessageHandler<T>registerDelegatingHandlers 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:
AddLoggingHandler()— attaches theLoggingHandlerfor structured request/response logging.AddInternalHeadersForwardingHandler()— attaches theInternalHeadersForwardHandlerfor service-to-service header propagation.
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.
ServiceCollectionExtensions
The ServiceCollectionExtensions class is the primary entry point for setting up HttpClient integrations within the .NET dependency injection container.
HttpClientBuilderExtensions
The HttpClientBuilderExtensions class provides extension members on IHttpClientBuilder (declared inside an extension(IHttpClientBuilder) block) that attach DelegatingHandlers to a typed client's message handler pipeline.
HttpRequestOptionsExtensions
The HttpRequestOptionsExtensions class provides extension members on HttpRequestOptions (declared inside an extension(HttpRequestOptions) block) for reading context that the hosting environment attaches to outgoing requests.