Table of Contents

Class EntityFrameworkServicesBuilder

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

A builder API designed for database providers to use when registering services.

public class EntityFrameworkServicesBuilder
Inheritance
EntityFrameworkServicesBuilder
Derived
Inherited Members

Remarks

Providers should create an instance of this class, use its methods to register services, and then call TryAddCoreServices() to fill out the remaining Entity Framework services.

Relational providers should use 'EntityFrameworkRelationalServicesBuilder instead.

Entity Framework ensures that services are registered with the appropriate scope. In some cases a provider may register a service with a different scope, but great care must be taken that all its dependencies can handle the new scope, and that it does not cause issue for services that depend on it.

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

Constructors

EntityFrameworkServicesBuilder(IServiceCollection)

Used by database providers to create a new EntityFrameworkServicesBuilder for registration of provider services. Relational providers should use 'EntityFrameworkRelationalServicesBuilder'.

public EntityFrameworkServicesBuilder(IServiceCollection serviceCollection)

Parameters

serviceCollection IServiceCollection

The collection to which services will be registered.

Remarks

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

Fields

CoreServices

This is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release. You should only use it directly in your code with extreme caution and knowing that doing so can result in application failures when updating to a new Entity Framework Core release.

[EntityFrameworkInternal]
public static readonly IDictionary<Type, ServiceCharacteristics> CoreServices

Field Value

IDictionary<Type, ServiceCharacteristics>

Remarks

This dictionary is exposed for testing and provider-validation only. It should not be used from application code.

Properties

ServiceCollectionMap

Access to the underlying ServiceCollectionMap.

protected virtual ServiceCollectionMap ServiceCollectionMap { get; }

Property Value

ServiceCollectionMap

Remarks

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

Methods

GetServiceCharacteristics(Type)

Gets the ServiceCharacteristics for the given service type.

protected virtual ServiceCharacteristics GetServiceCharacteristics(Type serviceType)

Parameters

serviceType Type

The type that defines the service API.

Returns

ServiceCharacteristics

The ServiceCharacteristics for the type.

Remarks

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

Exceptions

InvalidOperationException

when the type is not an EF service.

TryAdd(Type, object)

Adds an implementation of an Entity Framework service only if one has not already been registered. This method can only be used for singleton services.

public virtual EntityFrameworkServicesBuilder TryAdd(Type serviceType, object implementation)

Parameters

serviceType Type

The contract for the service.

implementation object

The implementation of the service.

Returns

EntityFrameworkServicesBuilder

This builder, such that further calls can be chained.

Remarks

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

TryAdd(Type, Type)

Adds an implementation of an Entity Framework service only if one has not already been registered. The scope of the service is automatically defined by Entity Framework.

public virtual EntityFrameworkServicesBuilder TryAdd(Type serviceType, Type implementationType)

Parameters

serviceType Type

The contract for the service.

implementationType Type

The concrete type that implements the service.

Returns

EntityFrameworkServicesBuilder

This builder, such that further calls can be chained.

Remarks

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

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

Adds a factory for an Entity Framework service only if one has not already been registered. The scope of the service is automatically defined by Entity Framework.

public virtual EntityFrameworkServicesBuilder TryAdd(Type serviceType, Type implementationType, Func<IServiceProvider, object> factory)

Parameters

serviceType Type

The contract for the service.

implementationType Type

The concrete type that implements the service.

factory Func<IServiceProvider, object>

The factory that will create the service instance.

Returns

EntityFrameworkServicesBuilder

This builder, such that further calls can be chained.

Remarks

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

TryAddCoreServices()

Registers default implementations of all services not already registered by the provider. Database providers must call this method as the last step of service registration--that is, after all provider services have been registered.

public virtual EntityFrameworkServicesBuilder TryAddCoreServices()

Returns

EntityFrameworkServicesBuilder

This builder, such that further calls can be chained.

Remarks

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

TryAddProviderSpecificServices(Action<ServiceCollectionMap>)

Database providers should call this method for access to the underlying ServiceCollectionMap such that provider-specific services can be registered. Note that implementations of Entity Framework services should be registered directly on the EntityFrameworkServicesBuilder and not through this method.

public virtual EntityFrameworkServicesBuilder TryAddProviderSpecificServices(Action<ServiceCollectionMap> serviceMap)

Parameters

serviceMap Action<ServiceCollectionMap>

The underlying map to which provider services should be added.

Returns

EntityFrameworkServicesBuilder

This builder, such that further calls can be chained.

Remarks

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

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

Adds a factory for an Entity Framework service only if one has not already been registered. The scope of the service is automatically defined by Entity Framework.

public virtual EntityFrameworkServicesBuilder TryAdd<TService>(Func<IServiceProvider, TService> factory) where TService : class

Parameters

factory Func<IServiceProvider, TService>

The factory that will create the service instance.

Returns

EntityFrameworkServicesBuilder

This builder, such that further calls can be chained.

Type Parameters

TService

The contract for the service.

Remarks

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

TryAdd<TService>(TService)

Adds an implementation of an Entity Framework service only if one has not already been registered. This method can only be used for singleton services.

public virtual EntityFrameworkServicesBuilder TryAdd<TService>(TService implementation) where TService : class

Parameters

implementation TService

The implementation of the service.

Returns

EntityFrameworkServicesBuilder

This builder, such that further calls can be chained.

Type Parameters

TService

The contract for the service.

Remarks

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

TryAdd<TService, TImplementation>()

Adds an implementation of an Entity Framework service only if one has not already been registered. The scope of the service is automatically defined by Entity Framework.

public virtual EntityFrameworkServicesBuilder TryAdd<TService, TImplementation>() where TService : class where TImplementation : class, TService

Returns

EntityFrameworkServicesBuilder

This builder, such that further calls can be chained.

Type Parameters

TService

The contract for the service.

TImplementation

The concrete type that implements the service.

Remarks

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

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

Adds a factory for an Entity Framework service only if one has not already been registered. The scope of the service is automatically defined by Entity Framework.

public virtual EntityFrameworkServicesBuilder TryAdd<TService, TImplementation>(Func<IServiceProvider, TImplementation> factory) where TService : class where TImplementation : class, TService

Parameters

factory Func<IServiceProvider, TImplementation>

The factory that will create the service instance.

Returns

EntityFrameworkServicesBuilder

This builder, such that further calls can be chained.

Type Parameters

TService

The contract for the service.

TImplementation

The concrete type that implements the service.

Remarks

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

TryGetServiceCharacteristics(Type)

Gets the ServiceCharacteristics for the given service type.

protected virtual ServiceCharacteristics? TryGetServiceCharacteristics(Type serviceType)

Parameters

serviceType Type

The type that defines the service API.

Returns

ServiceCharacteristics?

The ServiceCharacteristics for the type or null if it's not an EF service.

Remarks

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