DbContextOptionsBuilder.ReplaceService<TService,TImplementation> Method


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

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.

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


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


The new implementation type for the service.


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

Applies to