Skip to content

Make NpgsqlDataSource a scoped service instead of singleton #3086

@roji

Description

@roji

NpgsqlDataSource is currently registered as a singleton service; although this conceptually makes sense, it creates various issues:

  • When automatically getting the data source from DI, there's no way in EF to include the data source instance in the decision-making on whether a new service provider is needed, causing interference between service providers (Using NpgsqlDataSource in DependencyInjection pollutes other containers #2891).
  • In some multi-tenant and testing scenarios, it's desirable to use many data sources with potentially the same EF service provider. In the current situation, this requires lots of EF service providers, which triggers our "many service providers" warning.

The main thing blocking making NpgsqlDataSource scoped is the fact that we get enum mappings from it in NpgsqlTypeMappingSource, which is itself a singleton. We should stop doing that (#3063), at which point it should be easy to make NpgsqlDataSource scoped.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions