Class ServiceCollectionExtensions
- Assembly
- Mokkit.Containers.Microsoft.Extensions.DependencyInjection.dll
Provides extension methods for Microsoft.Extensions.DependencyInjection.IServiceCollection to enable stage-based service resolution. These extensions allow services to be resolved from the test stage context rather than the DI container.
public static class ServiceCollectionExtensionsInheritance
Inherited Members
Methods
ResolveFromStage<T>(IServiceCollection, ServiceLifetime)
Registers a service of type T to be resolved from the test stage context.
This method allows services to be resolved from the test host bag rather than the DI container.
public static IServiceCollection ResolveFromStage<T>(this IServiceCollection services, ServiceLifetime lifetime = ServiceLifetime.Transient)Parameters
servicesIServiceCollection-
The service collection to add the registration to.
lifetimeServiceLifetime-
The service lifetime for the registration. Defaults to Microsoft.Extensions.DependencyInjection.ServiceLifetime.Transient.
Returns
- IServiceCollection
-
The service collection for method chaining.
Type Parameters
T-
The type of service to register for stage resolution.
ResolveFromStage(IServiceCollection, Type, ServiceLifetime)
Registers a service of the specified type to be resolved from the test stage context. This method creates a service descriptor that uses Mokkit.Containers.IStageResolve to resolve services from the test host bag.
public static IServiceCollection ResolveFromStage(this IServiceCollection services, Type serviceType, ServiceLifetime lifetime = ServiceLifetime.Transient)Parameters
servicesIServiceCollection-
The service collection to add the registration to.
serviceTypeType-
The type of service to register for stage resolution.
lifetimeServiceLifetime-
The service lifetime for the registration. Defaults to Microsoft.Extensions.DependencyInjection.ServiceLifetime.Transient.
Returns
- IServiceCollection
-
The service collection for method chaining.
Exceptions
- InvalidOperationException
-
Thrown when the service cannot be resolved from the stage context.