Skip to content

Allow pooling DbContext with singleton services #27752

@stevendarby

Description

@stevendarby

When using DbContext pooling, the DbContext can't have a constructor which takes anything but DbContextOptions. I would like to be able to inject singleton services - can this be allowed?

The example of how to use pooling in a multi-tenanted application is useful, however in my app we have a tenant ID accessor which is a singleton service that acts similarly to HttpContextAccessor. As such I was hoping to be able to inject this into my DbContext, even with pooling enabled. It's much nicer to be able to declare the dependencies in the constructor, and because it's a singleton service I don't think it matters that the DbContext instance is pooled?

If DbContext pooling is going to be pushed more aggressively, it might be nice to review ways to make it easier to use - such as this.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions