Table of Contents

Class PooledDbContextFactory<TContext>

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

A factory returning pooled DbContext instances. Disposing the instance returned by this factory returns them to the internal pooling mechanism.

public class PooledDbContextFactory<TContext> : IDbContextFactory<TContext> where TContext : DbContext

Type Parameters

TContext
Inheritance
PooledDbContextFactory<TContext>
Implements
Inherited Members

Remarks

A service of this type is registered in the dependency injection container by the methods.

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

Constructors

PooledDbContextFactory(DbContextOptions<TContext>, int)

Initializes a new instance of the PooledDbContextFactory<TContext> class.

public PooledDbContextFactory(DbContextOptions<TContext> options, int poolSize = 1024)

Parameters

options DbContextOptions<TContext>

The options to use for contexts produced by this factory.

poolSize int

Sets the maximum number of instances retained by the pool. Defaults to 1024.

PooledDbContextFactory(IDbContextPool<TContext>)

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 PooledDbContextFactory(IDbContextPool<TContext> pool)

Parameters

pool IDbContextPool<TContext>

Methods

CreateDbContext()

public virtual TContext CreateDbContext()

Returns

TContext

CreateDbContextAsync(CancellationToken)

public virtual Task<TContext> CreateDbContextAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Returns

Task<TContext>