DEV Community

Julia Shevchenko
Julia Shevchenko

Posted on

2

Adding another database provider (for testing) is not working in EF Core 9

For writing integration tests, a common approach is to change the database provider, for example, to the InMemory database. But with Ef Core 9 this approach will give you an exception: "Only a single database provider can be registered in a service provider". So, what to do if there is a need to change the database provider and even manually removing another provider doesn't help?

Image description

Searching for possible solutions, I've found this issue on the ef core repository.
It turned out that a new IDbContextOptionsConfiguration interface was introduced, which, according to the documentation, configures the options to be used by a DbContext. And if it tracks multiple database providers, the exception will be thrown.

A workaround that I found in this article is to remove the configuration from the service provider. This solution works like a charm but feels a little bit hacky. Should we manually change the configuration? However, this may still save hours for those who faced it after updating the ef core.

The current version of the documentation here is not updated yet. However, the issue is in progress, and I'm curious what the suggested solution will be.

Heroku

Built for developers, by developers.

Whether you're building a simple prototype or a business-critical product, Heroku's fully-managed platform gives you the simplest path to delivering apps quickly — using the tools and languages you already love!

Learn More

Top comments (1)

Collapse
 
chami profile image
Mohammed Chami • Edited

thank you for sharing

ACI image

ACI.dev: Fully Open-source AI Agent Tool-Use Infra (Composio Alternative)

100% open-source tool-use platform (backend, dev portal, integration library, SDK/MCP) that connects your AI agents to 600+ tools with multi-tenant auth, granular permissions, and access through direct function calling or a unified MCP server.

Check out our GitHub!