Table of Contents

Class ServiceCollectionMap

Namespace
Microsoft.EntityFrameworkCore.Infrastructure
Assembly
Microsoft.EntityFrameworkCore.dll

Provides a map over a IServiceCollection that allows ServiceDescriptor entries to be conditionally added or re-written without requiring linear scans of the service collection each time this is done.

public class ServiceCollectionMap : IInfrastructure<IInternalServiceCollectionMap>
Inheritance
ServiceCollectionMap
Implements
Inherited Members
Extension Methods

Remarks

Note that the collection should not be modified without in other ways while it is being managed by the map. The collection can be used in the normal way after modifications using the map have been completed.

See Implementation of database providers and extensions for more information and examples.

Constructors

ServiceCollectionMap(IServiceCollection)

Creates a new ServiceCollectionMap to operate on the given IServiceCollection.

public ServiceCollectionMap(IServiceCollection serviceCollection)

Parameters

serviceCollection IServiceCollection

The collection to work with.

Properties

ServiceCollection

The underlying IServiceCollection.

public virtual IServiceCollection ServiceCollection { get; }

Property Value

IServiceCollection

Methods

TryAdd(Type, Func<IServiceProvider, object>, ServiceLifetime)

Adds a service implemented by the given factory if no service for the given service type has already been registered.

public virtual ServiceCollectionMap TryAdd(Type serviceType, Func<IServiceProvider, object> factory, ServiceLifetime lifetime)

Parameters

serviceType Type

The contract for the service.

factory Func<IServiceProvider, object>

The factory that implements the service.

lifetime ServiceLifetime

The service lifetime.

Returns

ServiceCollectionMap

The map, such that further calls can be chained.

TryAdd(Type, Type, ServiceLifetime)

Adds a service implemented by the given concrete type if no service for the given service type has already been registered.

public virtual ServiceCollectionMap TryAdd(Type serviceType, Type implementationType, ServiceLifetime lifetime)

Parameters

serviceType Type

The contract for the service.

implementationType Type

The concrete type that implements the service.

lifetime ServiceLifetime

The service lifetime.

Returns

ServiceCollectionMap

The map, such that further calls can be chained.

TryAddEnumerable(Type, Type, ServiceLifetime)

Adds a service implemented by the given concrete type to the list of services that implement the given contract. The service is only added if the collection contains no other registration for the same service and implementation type.

public virtual ServiceCollectionMap TryAddEnumerable(Type serviceType, Type implementationType, ServiceLifetime lifetime)

Parameters

serviceType Type

The contract for the service.

implementationType Type

The concrete type that implements the service.

lifetime ServiceLifetime

The service lifetime.

Returns

ServiceCollectionMap

The map, such that further calls can be chained.

TryAddEnumerable(Type, Type, Func<IServiceProvider, object>, ServiceLifetime)

Adds a service implemented by the given factory to the list of services that implement the given contract. The service is only added if the collection contains no other registration for the same service and implementation type.

public virtual ServiceCollectionMap TryAddEnumerable(Type serviceType, Type implementationType, Func<IServiceProvider, object> factory, ServiceLifetime lifetime)

Parameters

serviceType Type

The contract for the service.

implementationType Type

The concrete type that implements the service.

factory Func<IServiceProvider, object>

The factory that implements this service.

lifetime ServiceLifetime

The service lifetime.

Returns

ServiceCollectionMap

The map, such that further calls can be chained.

TryAddScoped(Type, Func<IServiceProvider, object>)

Adds a Scoped service implemented by the given factory if no service for the given service type has already been registered.

public virtual ServiceCollectionMap TryAddScoped(Type serviceType, Func<IServiceProvider, object> factory)

Parameters

serviceType Type

The contract for the service.

factory Func<IServiceProvider, object>

The factory that implements the service.

Returns

ServiceCollectionMap

The map, such that further calls can be chained.

TryAddScoped(Type, Type)

Adds a Scoped service implemented by the given concrete type if no service for the given service type has already been registered.

public virtual ServiceCollectionMap TryAddScoped(Type serviceType, Type implementationType)

Parameters

serviceType Type

The contract for the service.

implementationType Type

The concrete type that implements the service.

Returns

ServiceCollectionMap

The map, such that further calls can be chained.

TryAddScopedEnumerable(Type, Type)

Adds a Scoped service implemented by the given concrete type to the list of services that implement the given contract. The service is only added if the collection contains no other registration for the same service and implementation type.

public virtual ServiceCollectionMap TryAddScopedEnumerable(Type serviceType, Type implementationType)

Parameters

serviceType Type

The contract for the service.

implementationType Type

The concrete type that implements the service.

Returns

ServiceCollectionMap

The map, such that further calls can be chained.

TryAddScopedEnumerable<TService, TImplementation>()

Adds a Scoped service implemented by the given concrete type to the list of services that implement the given contract. The service is only added if the collection contains no other registration for the same service and implementation type.

public virtual ServiceCollectionMap TryAddScopedEnumerable<TService, TImplementation>() where TService : class where TImplementation : class, TService

Returns

ServiceCollectionMap

The map, such that further calls can be chained.

Type Parameters

TService

The contract for the service.

TImplementation

The concrete type that implements the service.

TryAddScopedEnumerable<TService, TImplementation>(Func<IServiceProvider, TImplementation>)

Adds a Scoped service implemented by the given factory to the list of services that implement the given contract. The service is only added if the collection contains no other registration for the same service and implementation type.

public virtual ServiceCollectionMap TryAddScopedEnumerable<TService, TImplementation>(Func<IServiceProvider, TImplementation> factory) where TService : class where TImplementation : class, TService

Parameters

factory Func<IServiceProvider, TImplementation>

The factory that implements this service.

Returns

ServiceCollectionMap

The map, such that further calls can be chained.

Type Parameters

TService

The contract for the service.

TImplementation

The concrete type that implements the service.

TryAddScoped<TService>(Func<IServiceProvider, TService>)

Adds a Scoped service implemented by the given factory if no service for the given service type has already been registered.

public virtual ServiceCollectionMap TryAddScoped<TService>(Func<IServiceProvider, TService> factory) where TService : class

Parameters

factory Func<IServiceProvider, TService>

The factory that implements the service.

Returns

ServiceCollectionMap

The map, such that further calls can be chained.

Type Parameters

TService

The contract for the service.

TryAddScoped<TService, TImplementation>()

Adds a Scoped service implemented by the given concrete type if no service for the given service type has already been registered.

public virtual ServiceCollectionMap TryAddScoped<TService, TImplementation>() where TService : class where TImplementation : class, TService

Returns

ServiceCollectionMap

The map, such that further calls can be chained.

Type Parameters

TService

The contract for the service.

TImplementation

The concrete type that implements the service.

TryAddScoped<TService, TImplementation>(Func<IServiceProvider, TImplementation>)

Adds a Scoped service implemented by the given factory if no service for the given service type has already been registered.

public virtual ServiceCollectionMap TryAddScoped<TService, TImplementation>(Func<IServiceProvider, TImplementation> factory) where TService : class where TImplementation : class, TService

Parameters

factory Func<IServiceProvider, TImplementation>

The factory that implements the service.

Returns

ServiceCollectionMap

The map, such that further calls can be chained.

Type Parameters

TService

The contract for the service.

TImplementation

The concrete type that the given factory creates.

TryAddSingleton(Type, Func<IServiceProvider, object>)

Adds a Singleton service implemented by the given factory if no service for the given service type has already been registered.

public virtual ServiceCollectionMap TryAddSingleton(Type serviceType, Func<IServiceProvider, object> factory)

Parameters

serviceType Type

The contract for the service.

factory Func<IServiceProvider, object>

The factory that implements the service.

Returns

ServiceCollectionMap

The map, such that further calls can be chained.

TryAddSingleton(Type, object)

Adds a Singleton service implemented by the given instance if no service for the given service type has already been registered.

public virtual ServiceCollectionMap TryAddSingleton(Type serviceType, object implementation)

Parameters

serviceType Type

The contract for the service.

implementation object

The object that implements the service.

Returns

ServiceCollectionMap

The map, such that further calls can be chained.

TryAddSingleton(Type, Type)

Adds a Singleton service implemented by the given concrete type if no service for the given service type has already been registered.

public virtual ServiceCollectionMap TryAddSingleton(Type serviceType, Type implementationType)

Parameters

serviceType Type

The contract for the service.

implementationType Type

The concrete type that implements the service.

Returns

ServiceCollectionMap

The map, such that further calls can be chained.

TryAddSingletonEnumerable(Type, object)

Adds a Singleton service implemented by the given instance to the list of services that implement the given contract. The service is only added if the collection contains no other registration for the same service and implementation type.

public virtual ServiceCollectionMap TryAddSingletonEnumerable(Type serviceType, object implementation)

Parameters

serviceType Type

The contract for the service.

implementation object

The object that implements the service.

Returns

ServiceCollectionMap

The map, such that further calls can be chained.

TryAddSingletonEnumerable(Type, Type)

Adds a Singleton service implemented by the given concrete type to the list of services that implement the given contract. The service is only added if the collection contains no other registration for the same service and implementation type.

public virtual ServiceCollectionMap TryAddSingletonEnumerable(Type serviceType, Type implementationType)

Parameters

serviceType Type

The contract for the service.

implementationType Type

The concrete type that implements the service.

Returns

ServiceCollectionMap

The map, such that further calls can be chained.

TryAddSingletonEnumerable<TService>(TService)

Adds a Singleton service implemented by the given instance to the list of services that implement the given contract. The service is only added if the collection contains no other registration for the same service and implementation type.

public virtual ServiceCollectionMap TryAddSingletonEnumerable<TService>(TService implementation) where TService : class

Parameters

implementation TService

The object that implements the service.

Returns

ServiceCollectionMap

The map, such that further calls can be chained.

Type Parameters

TService

The contract for the service.

TryAddSingletonEnumerable<TService, TImplementation>()

Adds a Singleton service implemented by the given concrete type to the list of services that implement the given contract. The service is only added if the collection contains no other registration for the same service and implementation type.

public virtual ServiceCollectionMap TryAddSingletonEnumerable<TService, TImplementation>() where TService : class where TImplementation : class, TService

Returns

ServiceCollectionMap

The map, such that further calls can be chained.

Type Parameters

TService

The contract for the service.

TImplementation

The concrete type that implements the service.

TryAddSingletonEnumerable<TService, TImplementation>(Func<IServiceProvider, TImplementation>)

Adds a Singleton service implemented by the given factory to the list of services that implement the given contract. The service is only added if the collection contains no other registration for the same service and implementation type.

public virtual ServiceCollectionMap TryAddSingletonEnumerable<TService, TImplementation>(Func<IServiceProvider, TImplementation> factory) where TService : class where TImplementation : class, TService

Parameters

factory Func<IServiceProvider, TImplementation>

The factory that implements this service.

Returns

ServiceCollectionMap

The map, such that further calls can be chained.

Type Parameters

TService

The contract for the service.

TImplementation

The concrete type that implements the service.

TryAddSingleton<TService>(Func<IServiceProvider, TService>)

Adds a Singleton service implemented by the given factory if no service for the given service type has already been registered.

public virtual ServiceCollectionMap TryAddSingleton<TService>(Func<IServiceProvider, TService> factory) where TService : class

Parameters

factory Func<IServiceProvider, TService>

The factory that implements the service.

Returns

ServiceCollectionMap

The map, such that further calls can be chained.

Type Parameters

TService

The contract for the service.

TryAddSingleton<TService>(TService)

Adds a Singleton service implemented by the given instance if no service for the given service type has already been registered.

public virtual ServiceCollectionMap TryAddSingleton<TService>(TService implementation) where TService : class

Parameters

implementation TService

The object that implements the service.

Returns

ServiceCollectionMap

The map, such that further calls can be chained.

Type Parameters

TService

The contract for the service.

TryAddSingleton<TService, TImplementation>()

Adds a Singleton service implemented by the given concrete type if no service for the given service type has already been registered.

public virtual ServiceCollectionMap TryAddSingleton<TService, TImplementation>() where TService : class where TImplementation : class, TService

Returns

ServiceCollectionMap

The map, such that further calls can be chained.

Type Parameters

TService

The contract for the service.

TImplementation

The concrete type that implements the service.

TryAddSingleton<TService, TImplementation>(Func<IServiceProvider, TImplementation>)

Adds a Singleton service implemented by the given factory if no service for the given service type has already been registered.

public virtual ServiceCollectionMap TryAddSingleton<TService, TImplementation>(Func<IServiceProvider, TImplementation> factory) where TService : class where TImplementation : class, TService

Parameters

factory Func<IServiceProvider, TImplementation>

The factory that implements the service.

Returns

ServiceCollectionMap

The map, such that further calls can be chained.

Type Parameters

TService

The contract for the service.

TImplementation

The concrete type that the given factory creates.

TryAddTransient(Type, Func<IServiceProvider, object>)

Adds a Transient service implemented by the given factory if no service for the given service type has already been registered.

public virtual ServiceCollectionMap TryAddTransient(Type serviceType, Func<IServiceProvider, object> factory)

Parameters

serviceType Type

The contract for the service.

factory Func<IServiceProvider, object>

The factory that implements the service.

Returns

ServiceCollectionMap

The map, such that further calls can be chained.

TryAddTransient(Type, Type)

Adds a Transient service implemented by the given concrete type if no service for the given service type has already been registered.

public virtual ServiceCollectionMap TryAddTransient(Type serviceType, Type implementationType)

Parameters

serviceType Type

The contract for the service.

implementationType Type

The concrete type that implements the service.

Returns

ServiceCollectionMap

The map, such that further calls can be chained.

TryAddTransientEnumerable(Type, Type)

Adds a Transient service implemented by the given concrete type to the list of services that implement the given contract. The service is only added if the collection contains no other registration for the same service and implementation type.

public virtual ServiceCollectionMap TryAddTransientEnumerable(Type serviceType, Type implementationType)

Parameters

serviceType Type

The contract for the service.

implementationType Type

The concrete type that implements the service.

Returns

ServiceCollectionMap

The map, such that further calls can be chained.

TryAddTransientEnumerable<TService, TImplementation>()

Adds a Transient service implemented by the given concrete type to the list of services that implement the given contract. The service is only added if the collection contains no other registration for the same service and implementation type.

public virtual ServiceCollectionMap TryAddTransientEnumerable<TService, TImplementation>() where TService : class where TImplementation : class, TService

Returns

ServiceCollectionMap

The map, such that further calls can be chained.

Type Parameters

TService

The contract for the service.

TImplementation

The concrete type that implements the service.

TryAddTransientEnumerable<TService, TImplementation>(Func<IServiceProvider, TImplementation>)

Adds a Transient service implemented by the given factory to the list of services that implement the given contract. The service is only added if the collection contains no other registration for the same service and implementation type.

public virtual ServiceCollectionMap TryAddTransientEnumerable<TService, TImplementation>(Func<IServiceProvider, TImplementation> factory) where TService : class where TImplementation : class, TService

Parameters

factory Func<IServiceProvider, TImplementation>

The factory that implements this service.

Returns

ServiceCollectionMap

The map, such that further calls can be chained.

Type Parameters

TService

The contract for the service.

TImplementation

The concrete type that implements the service.

TryAddTransient<TService>(Func<IServiceProvider, TService>)

Adds a Transient service implemented by the given factory if no service for the given service type has already been registered.

public virtual ServiceCollectionMap TryAddTransient<TService>(Func<IServiceProvider, TService> factory) where TService : class

Parameters

factory Func<IServiceProvider, TService>

The factory that implements the service.

Returns

ServiceCollectionMap

The map, such that further calls can be chained.

Type Parameters

TService

The contract for the service.

TryAddTransient<TService, TImplementation>()

Adds a Transient service implemented by the given concrete type if no service for the given service type has already been registered.

public virtual ServiceCollectionMap TryAddTransient<TService, TImplementation>() where TService : class where TImplementation : class, TService

Returns

ServiceCollectionMap

The map, such that further calls can be chained.

Type Parameters

TService

The contract for the service.

TImplementation

The concrete type that implements the service.

TryAddTransient<TService, TImplementation>(Func<IServiceProvider, TImplementation>)

Adds a Transient service implemented by the given factory if no service for the given service type has already been registered.

public virtual ServiceCollectionMap TryAddTransient<TService, TImplementation>(Func<IServiceProvider, TImplementation> factory) where TService : class where TImplementation : class, TService

Parameters

factory Func<IServiceProvider, TImplementation>

The factory that implements the service.

Returns

ServiceCollectionMap

The map, such that further calls can be chained.

Type Parameters

TService

The contract for the service.

TImplementation

The concrete type that the given factory creates.