EmptyServiceProvider Class

Definition

Provides an IServiceProvider that contains no application services.

public ref class EmptyServiceProvider sealed : IServiceProvider, Microsoft::Extensions::DependencyInjection::IKeyedServiceProvider, Microsoft::Extensions::DependencyInjection::IServiceProviderIsKeyedService
public sealed class EmptyServiceProvider : IServiceProvider, Microsoft.Extensions.DependencyInjection.IKeyedServiceProvider, Microsoft.Extensions.DependencyInjection.IServiceProviderIsKeyedService
type EmptyServiceProvider = class
    interface IKeyedServiceProvider
    interface IServiceProvider
    interface IServiceProviderIsKeyedService
    interface IServiceProviderIsService
Public NotInheritable Class EmptyServiceProvider
Implements IKeyedServiceProvider, IServiceProvider, IServiceProviderIsKeyedService
Inheritance
EmptyServiceProvider
Implements

Remarks

Like the IServiceProvider returned by new ServiceCollection().BuildServiceProvider(), this provider still exposes the built-in services (IServiceProvider, IServiceScopeFactory, IServiceProviderIsService and IServiceProviderIsKeyedService) and resolves requests for IEnumerable<T> to an empty sequence.

Use Instance to access the shared singleton instead of writing a custom empty provider.

Properties

Name Description
Instance

Gets the shared EmptyServiceProvider instance.

Explicit Interface Implementations

Name Description
IKeyedServiceProvider.GetKeyedService(Type, Object)

Gets the service object of the specified type.

IKeyedServiceProvider.GetRequiredKeyedService(Type, Object)

Gets service of type serviceType from the IServiceProvider implementing this interface.

IServiceProvider.GetService(Type)

Gets the service object of the specified type.

IServiceProviderIsKeyedService.IsKeyedService(Type, Object)

Determines if the specified service type with the specified service key is available from the IServiceProvider.

IServiceProviderIsService.IsService(Type)

Determines if the specified service type is available from the IServiceProvider.

Extension Methods

Name Description
CreateAsyncScope(IServiceProvider)

Creates a new AsyncServiceScope that can be used to resolve scoped services.

CreateScope(IServiceProvider)

Creates a new IServiceScope that can be used to resolve scoped services.

GetFakeLogCollector(IServiceProvider)

Gets the object that collects log records sent to the fake logger.

GetFakeRedactionCollector(IServiceProvider)

Gets the fake redactor collector instance from the dependency injection container.

GetKeyedService(IServiceProvider, Type, Object)

Get service of type serviceType from the IServiceProvider.

GetKeyedService<T>(IServiceProvider, Object)

Get service of type T from the IServiceProvider.

GetKeyedServices(IServiceProvider, Type, Object)

Get an enumeration of services of type serviceType from the IServiceProvider.

GetKeyedServices<T>(IServiceProvider, Object)

Get an enumeration of services of type T from the IServiceProvider.

GetRequiredKeyedService(IServiceProvider, Type, Object)

Get service of type serviceType from the IServiceProvider.

GetRequiredKeyedService<T>(IServiceProvider, Object)

Get service of type T from the IServiceProvider.

GetRequiredService(IServiceProvider, Type)

Get service of type serviceType from the IServiceProvider.

GetRequiredService<T>(IServiceProvider)

Get service of type T from the IServiceProvider.

GetService<T>(IServiceProvider)

Get service of type T from the IServiceProvider.

GetServices(IServiceProvider, Type)

Get an enumeration of services of type serviceType from the IServiceProvider.

GetServices<T>(IServiceProvider)

Get an enumeration of services of type T from the IServiceProvider.

Applies to