-
Notifications
You must be signed in to change notification settings - Fork 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
Document best practices for stateful context pooling #3706
Comments
@GregJF the documentation describes a limitation in the way DbContext pooling works; since context instances are pooled across requests, the lifetime of each context instance is effectively like a singleton-registered service (although the context instances themselves aren't directly registered in DI at all). This is a fundamental characteristic of how pooling works. However, we should probably add some guidance on how to work with pooled contexts that need to vary state across requests (i.e. scoped IDbContextFactory, DbConnection interception for connection strings). dotnet/efcore#14625 has some discussion around these. /cc @ajcvickers |
And rearrange the perf docs a little Closes dotnet#3706
And rearrange the perf docs a little Closes dotnet#3706
And rearrange the perf docs a little Closes dotnet#3706
And rearrange the perf docs a little Closes dotnet#3706
And rearrange the perf docs a little Closes dotnet#3706
And rearrange the perf docs a little Closes dotnet#3706
And rearrange the perf docs a little Closes #3706
[Enter feedback here]
You said
registering a dbContext as Singleton is not advisable as all users will share the same instance for the life of the application
The better way is to register dbContext as Scoped (in .net core) or webRequest (in most IoC products)
Regards
GregJF
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
The text was updated successfully, but these errors were encountered: