-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Make DbContext pooling accessible to non-DI applications #24137
Comments
@roji I notice you mention it is possible to set up pooling without DI, would you be able to cite any examples of how to implement this? It would be an amazing help! |
Here's a way to do it: var optionsBuilder = new DbContextOptionsBuilder<FortunesContext>();
// Configure context options
var pool = new DbContextPool<FortunesContext>(optionsBuilder.options);
// Now that you have a pool, you can use it as follows:
var poolable = _contextPool.Rent();
poolable.SetLease(new DbContextLease(_contextPool, standalone: true));
using var dbContext = (FortunesContext)poolable; However, note again the above uses internal APIs, and so may break in future releases. |
As discussed with @ajcvickers offline, bypassing DI in the TE Fortunes benchmark yields around 2.8% RPS. So I'll be doing this for 6.0.0. |
The setup of DbContext pooling is currently tied to DI. While it's possible to set it up without DI, that currently requires using internal types.
The text was updated successfully, but these errors were encountered: