Table of Contents

Class DependencyInjectionExtension

Namespace
Xping.Sdk.Core.DependencyInjection
Assembly
Xping.Sdk.Core.dll

Provides extension methods for the IServiceCollection interface to register test-related services.

public static class DependencyInjectionExtension
Inheritance
DependencyInjectionExtension
Inherited Members

Methods

AddBrowserClientFactory(IServiceCollection)

This extension method adds the necessary factory service to create headless browser instance into your application’s service collection.

public static IServiceCollection AddBrowserClientFactory(this IServiceCollection services)

Parameters

services IServiceCollection

The IServiceCollection.

Returns

IServiceCollection

IServiceCollection object.

AddHttpClientFactory(IServiceCollection, Action<IServiceProvider, HttpClientFactoryConfiguration>?)

This extension method adds the IHttpClientFactory service and related services to service collection and configures a named HttpClient clients.

public static IServiceCollection AddHttpClientFactory(this IServiceCollection services, Action<IServiceProvider, HttpClientFactoryConfiguration>? configuration = null)

Parameters

services IServiceCollection

The IServiceCollection.

configuration Action<IServiceProvider, HttpClientFactoryConfiguration>

The HttpClientFactoryConfiguration.

Returns

IServiceCollection

IServiceCollection object.

AddTestAgent(IServiceCollection)

Adds a default test agent to the service collection.

public static IServiceCollection AddTestAgent(this IServiceCollection services)

Parameters

services IServiceCollection

The service collection to add the service to.

Returns

IServiceCollection

The same service collection.

AddTestAgent(IServiceCollection, Action<TestAgent>)

Adds a test agent to the service collection.

public static IServiceCollection AddTestAgent(this IServiceCollection services, Action<TestAgent> builder)

Parameters

services IServiceCollection

The service collection to add the service to.

builder Action<TestAgent>

A function that configures the test agent instance.

Returns

IServiceCollection

The same service collection.

AddTestAgent(IServiceCollection, string, Action<TestAgent>)

Adds a named test agent to the service collection.

public static IServiceCollection AddTestAgent(this IServiceCollection services, string name, Action<TestAgent> builder)

Parameters

services IServiceCollection

The service collection to add the service to.

name string

The name of the test agent.

builder Action<TestAgent>

A function that configures the test agent instance.

Returns

IServiceCollection

The same service collection.

AddTestServerHttpClientFactory(IServiceCollection, Func<WebApplicationFactoryClientOptions, HttpClient>)

Adds an IHttpClientFactory implemented by WebApplicationHttpClientFactory to the service collection. This factory is specifically designed to align with system requirements for returning HttpClient instances produced by WebApplicationFactory.

public static IServiceCollection AddTestServerHttpClientFactory(this IServiceCollection services, Func<WebApplicationFactoryClientOptions, HttpClient> createClient)

Parameters

services IServiceCollection

The service collection to add the service to.

createClient Func<WebApplicationFactoryClientOptions, HttpClient>

A function that creates an HttpClient instance, typically WebApplicationFactory.CreateClient method.

Returns

IServiceCollection

The same service collection.

Remarks

The IHttpClientFactory provides a central location for creating and configuring HttpClient instances. It ensures efficient reuse of HttpClient instances, manages their lifetime, and allows customization of their behavior. The WebApplicationHttpClientFactory is tailored to work seamlessly with WebApplicationFactory and its associated services.

IsServiceRegistered<TService>(IServiceCollection)

Checks if a specific service type is already registered in the service collection.

public static bool IsServiceRegistered<TService>(this IServiceCollection services)

Parameters

services IServiceCollection

The IServiceCollection instance to search in.

Returns

bool

True if the service type is registered; otherwise, false.

Type Parameters

TService

The type of the service to check for registration.