ServiceCollectionExtensions
Namespace: BlazorNative.Http
DI registration for BlazorNative's HTTP bridge: extensions that wire
BridgeHttpHandler as the primary handler so HttpClient and
IHttpClientFactory route through the native shell (see
ServiceCollectionExtensions.AddBlazorNativeHttp(IServiceCollection) for the default client, and the
AddBlazorNativeHttpClient overloads for typed/named clients).
public static class ServiceCollectionExtensions
Inheritance Object → ServiceCollectionExtensions
Attributes NullableContextAttribute, NullableAttribute, ExtensionAttribute
Methods
AddBlazorNativeHttp(IServiceCollection)
Registers HttpClient with BridgeHttpHandler as the primary handler. All HttpClient injections will route through IMobileBridge.FetchAsync, so the native shell performs the actual HTTP request.
// In your DI setup (the runtime composition root — HostSession — or a test harness):
services.AddBlazorNativeHttp();
// In your services — no changes needed:
public class WeatherService(HttpClient http) { ... }
public static IServiceCollection AddBlazorNativeHttp(IServiceCollection services)
Parameters
services IServiceCollection
Returns
AddBlazorNativeHttpClient<TClient>(IServiceCollection, String)
Register a typed HttpClient with BridgeHttpHandler and optional base address.
services.AddBlazorNativeHttpClient<WeatherService>("https://api.weather.com");
public static IHttpClientBuilder AddBlazorNativeHttpClient<TClient>(IServiceCollection services, string? baseAddress = null) where TClient : class
Type Parameters
TClient
Parameters
services IServiceCollection
baseAddress String?
Returns
AddBlazorNativeHttpClient(IServiceCollection, String, String)
Register a named HttpClient with BridgeHttpHandler.
services.AddBlazorNativeHttpClient("weather", "https://api.weather.com");
// Inject via IHttpClientFactory and call CreateClient("weather")
public static IHttpClientBuilder AddBlazorNativeHttpClient(IServiceCollection services, string name, string? baseAddress = null)
Parameters
services IServiceCollection
name String
baseAddress String?