Language

EntityFrameworkServiceCollectionExtensions.RemoveDbContext<TContext> Method

Definition

Removes services for the given context type from the IServiceCollection.

public static Microsoft.Extensions.DependencyInjection.IServiceCollection RemoveDbContext<TContext>(this Microsoft.Extensions.DependencyInjection.IServiceCollection serviceCollection, bool removeConfigurationOnly = false) where TContext : Microsoft.EntityFrameworkCore.DbContext;
static member RemoveDbContext : Microsoft.Extensions.DependencyInjection.IServiceCollection * bool -> Microsoft.Extensions.DependencyInjection.IServiceCollection (requires 'Context :> Microsoft.EntityFrameworkCore.DbContext)
<Extension()>
Public Function RemoveDbContext(Of TContext As DbContext) (serviceCollection As IServiceCollection, Optional removeConfigurationOnly As Boolean = false) As IServiceCollection

Type Parameters

TContext

The type of context to be removed.

Parameters

serviceCollection
IServiceCollection

The IServiceCollection to remove services from.

removeConfigurationOnly
Boolean

If true, only the IDbContextOptionsConfiguration<TContext> registrations will be removed; the context itself will remain registered. If false (the default), all services related to the context will be removed.

Returns

The same service collection so that multiple calls can be chained.

Remarks

This method can be used to remove the context registration in integration testing scenarios where a different database provider is used for tests.

See Using DbContext with dependency injection for more information and examples.

Applies to