You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Make AddPooledDbContextFactory register DbContext in addition to the and factory #26528
In #25164 it was suggested that EF Core implicitly registers a scoped DbContext as well when AddDbContextFactory is used, which I thought was a great idea, and it was done in RC1 I think.
But why not do the same thing for AddPooledDbContextFactory too?! I'm using AddPooledDbContextFactory in my project and I was surprised to see that the same thing isn't done in that method as well.
Reacted by Marc Sallin, Meinrad Jean-Richard, Arad Alvand, Artur Gordashnikov, Ciaran Liedeman, Andrej Križan, Yann Zahringer Ferrando, Xamir, ROMYIM, aetos and 2 more
changed the title [-]Register a scoped DbContext automatically when using `AddPooledDbContextFactory` as well[/-][+]Register a scoped `DbContext` automatically when using `AddPooledDbContextFactory` as well[/+]on Nov 3, 2021
changed the title [-]Register a scoped `DbContext` automatically when using `AddPooledDbContextFactory` as well[/-][+]Register a scoped `DbContext` automatically when using `AddPooledDbContextFactory`[/+]on Nov 11, 2021
Same situation here. We use AddPooledDbContextFactory in all projects but we also use the EF HealthChecks, which expect the DbContext as ctor parameter. Hence, we also have to call AddDbContextPool<T>.
@ajcvickers Hi there, any reason as to why this was removed from 7.0.0? It seems like it would be relatively straightforward and simple to implement.
Thank you.
@aradalvand We had to punt a number of smaller issues. While each in itself would not take a long time, that time quickly adds up. This one is also only sugar--it's easy to obtain the same functionality by registering trice--which makes it lower priority.
changed the title [-]Register both DbContext and factory in DI with a single call[/-][+]Make AddPooledDbContextFactory register DbContext in addition to the and factory[/+]on Jan 16, 2025
All of our applications register the DbContextFactory by default (even if they may not use it) opposed to DbContext: it looks like we had an app that injected a scoped level value into DbContext, which had been working fine with the pre-v10 setup, since they never injected DbContextFactory; it took a bit to dig into why that was happening.
It wouldn't have been an issue had they originally marked the factory as being at the scope level, but it was a bit confusing as to why that had been working and suddenly stopped
Activity
[-]Register a scoped DbContext automatically when using `AddPooledDbContextFactory` as well[/-][+]Register a scoped `DbContext` automatically when using `AddPooledDbContextFactory` as well[/+][-]Register a scoped `DbContext` automatically when using `AddPooledDbContextFactory` as well[/-][+]Register a scoped `DbContext` automatically when using `AddPooledDbContextFactory`[/+]msallin commentedon Dec 28, 2021
Same situation here. We use
AddPooledDbContextFactoryin all projects but we also use the EF HealthChecks, which expect theDbContextas ctor parameter. Hence, we also have to callAddDbContextPool<T>.aradalvand commentedon Jul 18, 2022
@ajcvickers Hi there, any reason as to why this was removed from 7.0.0? It seems like it would be relatively straightforward and simple to implement.
Thank you.
ajcvickers commentedon Jul 18, 2022
@aradalvand We had to punt a number of smaller issues. While each in itself would not take a long time, that time quickly adds up. This one is also only sugar--it's easy to obtain the same functionality by registering trice--which makes it lower priority.
14 remaining items
[-]Register both DbContext and factory in DI with a single call[/-][+]Make AddPooledDbContextFactory register DbContext in addition to the and factory[/+]Fixes to implicit DbContext registration around factories
Fixes to implicit DbContext registration around factories (dotnet#35486)
susickypavel commentedon May 9, 2025
@roji Based on the labels I believe this was released as a part of .NET 10 preview 1?
Until .NET 10 is released it is ok for lower versions to register the
TContextwith following code?Will be the
BlogContextreturned from the pool if request through DI this way? Thank you for clarification.roji commentedon May 12, 2025
@susickypavel yes.
JohnYoungers commentedon Dec 18, 2025
It might be a good idea to call this out as a notable change here: https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-10.0/breaking-changes
All of our applications register the
DbContextFactoryby default (even if they may not use it) opposed toDbContext: it looks like we had an app that injected a scoped level value intoDbContext, which had been working fine with the pre-v10 setup, since they never injectedDbContextFactory; it took a bit to dig into why that was happening.It wouldn't have been an issue had they originally marked the factory as being at the scope level, but it was a bit confusing as to why that had been working and suddenly stopped