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?
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.
Top comments (1)
thank you for sharing