dotnet / dotnet/efcore

Support multiple constructors with DbContext pooling

Open
#35,620 5 comments 2 reactions 0 assignees View on GitHub
area-dbcontext customer-reported needs-design
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

### What problem are you trying to solve?

DbContext pooling doesn't work if the DbContext has multiple constructors.

I think this is a bit too strict, as only one constructor is needed with exactly one parameter DbContextOptions.

An usecase for multiple constructors for example is with the tool Linqpad but you need to separate constructor to use it for Linqpad.

The error thrown is `The DbContext of type '{contextType}' cannot be pooled because it does not have a public constructor accepting a single parameter of type DbContextOptions or has more than one constructor.`

The check is present in DbContextPool.CreateActivator() and could be changed to only check if a constructor is available with 1 parameter of type `typeof(DbContextOptions) || p.ParameterType == typeof(DbContextOptions))`

### Describe the solution you'd like

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.