Skip to main content

ServiceCollectionExtensions Class

Axios.Net.Extensions.DependencyInjection › AxiosNet.Extensions.DependencyInjection

Dependency injection extensions for AxiosClient.

public static class ServiceCollectionExtensions

Inheritance System.Object → ServiceCollectionExtensions

Methods​

ServiceCollectionExtensions.AddAxios(this IServiceCollection, Action<AxiosRequestConfig>) Method​

Registers AxiosClient as a singleton. Its requests go through the Axios.Net named System.Net.Http.IHttpClientFactory client, so handlers can be chained with AddHttpClient("Axios.Net").AddHttpMessageHandler<T>().

public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddAxios(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, System.Action<AxiosNet.Config.AxiosRequestConfig>? configure=null);

Parameters​

services Microsoft.Extensions.DependencyInjection.IServiceCollection

The service collection to add the client to.

configure System.Action<AxiosRequestConfig>

Sets the defaults merged into every request of the client.

Returns​

Microsoft.Extensions.DependencyInjection.IServiceCollection
The same service collection, for chaining.

Remarks​

The handler comes from the factory, so MaxRedirects, Decompress and Proxy are no longer read from the request config: configure them on the primary handler. The singleton keeps the handler it was created with, so it is not recycled and DNS changes are not picked up.