Class ServiceProviderTestExtensions
Provides typed service-provider helpers for framework-heavy test setup.
Inherited Members
Namespace: FastMoq.Extensions
Assembly: FastMoq.Core.dll
Syntax
public static class ServiceProviderTestExtensions
Methods
AddServiceProvider(Mocker, Action<IServiceCollection>?, bool, bool)
Builds and registers a typed IServiceProvider for the current Mocker instance.
Declaration
public static Mocker AddServiceProvider(this Mocker mocker, Action<IServiceCollection>? configureServices, bool replace = false, bool includeMockerFallback = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Mocker | mocker | The current Mocker instance. |
| Action<IServiceCollection> | configureServices | Optional service registrations to apply before the provider is built. |
| bool | replace | True to replace an existing registration. |
| bool | includeMockerFallback | True to fall back to the current Mocker for unregistered class and interface resolutions. |
Returns
| Type | Description |
|---|---|
| Mocker | The current Mocker instance. |
Remarks
This overload remains available for compatibility. Prefer AddTypedServiceProvider(Mocker, Action<IServiceCollection>?, bool, bool) for new typed service-provider registrations built from service descriptors.
AddServiceProvider(Mocker, IServiceProvider, bool)
Registers a typed IServiceProvider for the current Mocker instance.
Declaration
public static Mocker AddServiceProvider(this Mocker mocker, IServiceProvider serviceProvider, bool replace = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Mocker | mocker | The current Mocker instance. |
| IServiceProvider | serviceProvider | The provider to register. |
| bool | replace | True to replace an existing registration. |
Returns
| Type | Description |
|---|---|
| Mocker | The current Mocker instance. |
AddServiceScope(Mocker, IServiceScope, bool)
Registers a typed IServiceScope for the current Mocker instance.
Declaration
public static Mocker AddServiceScope(this Mocker mocker, IServiceScope serviceScope, bool replace = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Mocker | mocker | The current Mocker instance. |
| IServiceScope | serviceScope | The scope to register. |
| bool | replace | True to replace an existing registration. |
Returns
| Type | Description |
|---|---|
| Mocker | The current Mocker instance. |
AddServiceScope(Mocker, Action<IServiceCollection>?, bool, bool)
Builds and registers a typed IServiceScope for the current Mocker instance.
Declaration
public static Mocker AddServiceScope(this Mocker mocker, Action<IServiceCollection>? configureServices, bool replace = false, bool includeMockerFallback = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Mocker | mocker | The current Mocker instance. |
| Action<IServiceCollection> | configureServices | Optional service registrations to apply before the scope is built. |
| bool | replace | True to replace an existing registration. |
| bool | includeMockerFallback | True to fall back to the current Mocker for unregistered class and interface resolutions. |
Returns
| Type | Description |
|---|---|
| Mocker | The current Mocker instance. |
Remarks
This overload remains available for compatibility. Prefer AddTypedServiceScope(Mocker, Action<IServiceCollection>?, bool, bool) for new typed scope registrations built from service descriptors.
AddServiceScope(Mocker, IServiceProvider, bool)
Registers a fixed IServiceScope backed by the supplied IServiceProvider for the current Mocker instance.
Declaration
public static Mocker AddServiceScope(this Mocker mocker, IServiceProvider serviceProvider, bool replace = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Mocker | mocker | The current Mocker instance. |
| IServiceProvider | serviceProvider | The provider to expose through the registered scope. |
| bool | replace | True to replace an existing registration. |
Returns
| Type | Description |
|---|---|
| Mocker | The current Mocker instance. |
AddTypedServiceProvider(Mocker, Action<IServiceCollection>?, bool, bool)
Builds and registers a typed IServiceProvider for the current Mocker instance.
Declaration
public static Mocker AddTypedServiceProvider(this Mocker mocker, Action<IServiceCollection>? configureServices = null, bool replace = false, bool includeMockerFallback = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Mocker | mocker | The current Mocker instance. |
| Action<IServiceCollection> | configureServices | Optional service registrations to apply before the provider is built. |
| bool | replace | True to replace an existing registration. |
| bool | includeMockerFallback | True to fall back to the current Mocker for unregistered class and interface resolutions. |
Returns
| Type | Description |
|---|---|
| Mocker | The current Mocker instance. |
Remarks
Prefer this typed builder overload when the current Mocker should own the resulting provider registration. Use AddServiceProvider(Mocker, IServiceProvider, bool) when you already have a provider instance to register.
AddTypedServiceScope(Mocker, Action<IServiceCollection>?, bool, bool)
Builds and registers a typed IServiceScope for the current Mocker instance.
Declaration
public static Mocker AddTypedServiceScope(this Mocker mocker, Action<IServiceCollection>? configureServices = null, bool replace = false, bool includeMockerFallback = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Mocker | mocker | The current Mocker instance. |
| Action<IServiceCollection> | configureServices | Optional service registrations to apply before the scope is built. |
| bool | replace | True to replace an existing registration. |
| bool | includeMockerFallback | True to fall back to the current Mocker for unregistered class and interface resolutions. |
Returns
| Type | Description |
|---|---|
| Mocker | The current Mocker instance. |
Remarks
Prefer this typed builder overload when the current Mocker should own the resulting scope registration. Use AddServiceScope(Mocker, IServiceScope, bool) or AddServiceScope(Mocker, IServiceProvider, bool) when you already have a scope or provider instance.
CreateTypedServiceProvider(Mocker, Action<IServiceCollection>?, bool)
Creates a typed IServiceProvider from the supplied service registrations.
Declaration
public static IServiceProvider CreateTypedServiceProvider(this Mocker mocker, Action<IServiceCollection>? configureServices = null, bool includeMockerFallback = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Mocker | mocker | The current Mocker instance. |
| Action<IServiceCollection> | configureServices | Optional service registrations to apply before the provider is built. |
| bool | includeMockerFallback | True to fall back to the current Mocker for unregistered class and interface resolutions. |
Returns
| Type | Description |
|---|---|
| IServiceProvider | A real service provider that resolves services by requested type. |
Examples
var serviceProvider = Mocks.CreateTypedServiceProvider(services =>
{
services.AddSingleton(new Uri("https://fastmoq.dev"));
services.AddOptions();
});
CreateTypedServiceScope(Mocker, Action<IServiceCollection>?, bool)
Creates a typed IServiceScope from the supplied service registrations.
Declaration
public static IServiceScope CreateTypedServiceScope(this Mocker mocker, Action<IServiceCollection>? configureServices = null, bool includeMockerFallback = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Mocker | mocker | The current Mocker instance. |
| Action<IServiceCollection> | configureServices | Optional service registrations to apply before the scope is built. |
| bool | includeMockerFallback | True to fall back to the current Mocker for unregistered class and interface resolutions. |
Returns
| Type | Description |
|---|---|
| IServiceScope | A real service scope whose ServiceProvider resolves services by requested type. |