Replies: 5 comments 4 replies
-
cc @roji |
Beta Was this translation helpful? Give feedback.
-
The advantages of DbContext pooling are explained here in the EF docs. In a nutshell, every DbContext internally has a number of non-shared services and initialization that it requires, and so instantiating a DbContext is a non-trivial amount of work (and allocates some amount of memory). DbContext pooling simply eliminates that overhead. I'm not sure what issues you're referring to exactly - DbContext pooling should interfere with either thread safety or entity tracking. If you need to vary state across DbContext instances (e.g. a tenant ID) then you may need to jump through some extra hoops, but that's generally doable (and documented in the link I posted above). |
Beta Was this translation helpful? Give feedback.
-
@roji Thanks, based on my experience a long time ago, it wasn't easy to handle the number of pooled dbContext and also getting a stale object twice, so I was curious to add an option and ask the caller to register a Pooling or just register as a Scoped. |
Beta Was this translation helpful? Give feedback.
-
@roji Still, my point is that it is better to give the caller this flexibility to decide whether to pool or not. If pooling is desired, then there should be an option to set poolSize (the default size is 1024). Thank you for the response. |
Beta Was this translation helpful? Give feedback.
-
@roji BUT this is inside Nuget package and not exposed! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I was checking database components for EF Core, like SqlServer, Postgres, or MySql, in all of them we used:
I know that it is a good practice for high-performance application but also brings some issues for entity tracking or maybe thread safety.
I just wanted to know what the benefits of using DbContext pooling? is it because of .NET Aspire and the way it handles connections and discovery?
Beta Was this translation helpful? Give feedback.
All reactions