Class PlatformHttpClientFactory
- Namespace
- Datafication.Core.Platform
- Assembly
- Datafication.Core.dll
Factory for creating and resolving System.Net.Http.HttpClient instances across different environments, ensuring compatibility with both Blazor and non-Blazor scenarios.
public static class PlatformHttpClientFactory
- Inheritance
-
objectPlatformHttpClientFactory
Methods
CreateHttpClient()
Creates or resolves an System.Net.Http.HttpClient instance.
public static HttpClient CreateHttpClient()
Returns
- HttpClient
An System.Net.Http.HttpClient instance, either resolved from dependency injection (DI) or instantiated directly if DI is unavailable.
Examples
var httpClient = PlatformHttpClientFactory.CreateHttpClient();
var response = await httpClient.GetStringAsync("https://example.com");
Remarks
In Blazor WebAssembly, this method tries to resolve the pre-configured System.Net.Http.HttpClient from the DI container. In other environments, it falls back to a manually instantiated instance.