Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple constructors with DbContext pooling #35620

Open
rgroenewoudt opened this issue Feb 11, 2025 · 0 comments
Open

Support multiple constructors with DbContext pooling #35620

rgroenewoudt opened this issue Feb 11, 2025 · 0 comments

Comments

@rgroenewoudt
Copy link

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<TContext>))

Describe the solution you'd like

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant