DbContextOptionsBuilder.ReplaceService Method

Definition

Overloads

ReplaceService<TService,TCurrentImplementation,TNewImplementation>()

Replaces the internal Entity Framework implementation of a specific implementation of a service contract with a different implementation.

ReplaceService<TService,TImplementation>()

Replaces all internal Entity Framework implementations of a service contract with a different implementation.

ReplaceService<TService,TCurrentImplementation,TNewImplementation>()

Replaces the internal Entity Framework implementation of a specific implementation of a service contract with a different implementation.

public virtual Microsoft.EntityFrameworkCore.DbContextOptionsBuilder ReplaceService<TService,TCurrentImplementation,TNewImplementation> () where TCurrentImplementation : TService where TNewImplementation : TService;
abstract member ReplaceService : unit -> Microsoft.EntityFrameworkCore.DbContextOptionsBuilder
override this.ReplaceService : unit -> Microsoft.EntityFrameworkCore.DbContextOptionsBuilder
Public Overridable Function ReplaceService(Of TService, TCurrentImplementation, TNewImplementation) () As DbContextOptionsBuilder

Type Parameters

TService

The type (usually an interface) that defines the contract of the service to replace.

TCurrentImplementation

The current implementation type for the service.

TNewImplementation

The new implementation type for the service.

Returns

The same builder instance so that multiple calls can be chained.

Remarks

This method is useful for replacing a single instance of services that can be legitimately registered multiple times in the EF internal service provider.

This method can only be used when EF is building and managing its internal service provider. If the service provider is being built externally and passed to UseInternalServiceProvider(IServiceProvider), then replacement services should be configured on that service provider before it is passed to EF.

The replacement service gets the same scope as the EF service that it is replacing.

See Using DbContextOptions for more information and examples.

Applies to

ReplaceService<TService,TImplementation>()

Replaces all internal Entity Framework implementations of a service contract with a different implementation.

public virtual Microsoft.EntityFrameworkCore.DbContextOptionsBuilder ReplaceService<TService,TImplementation> () where TImplementation : TService;
abstract member ReplaceService : unit -> Microsoft.EntityFrameworkCore.DbContextOptionsBuilder
override this.ReplaceService : unit -> Microsoft.EntityFrameworkCore.DbContextOptionsBuilder
Public Overridable Function ReplaceService(Of TService, TImplementation) () As DbContextOptionsBuilder

Type Parameters

TService

The type (usually an interface) that defines the contract of the service to replace.

TImplementation

The new implementation type for the service.

Returns

The same builder instance so that multiple calls can be chained.

Remarks

This method can only be used when EF is building and managing its internal service provider. If the service provider is being built externally and passed to UseInternalServiceProvider(IServiceProvider), then replacement services should be configured on that service provider before it is passed to EF.

The replacement service gets the same scope as the EF service that it is replacing.

See Using DbContextOptions for more information and examples.

Applies to