Page 1 of 1

"More than twenty 'IServiceProvider' instances" error with multitenancy

Posted: Tue 09 Jun 2020 07:56
by TheCoolest
The product we are working on has multi tenancy support. This means that we have multiple different schemas\users.
After opening a connection to more than 20 schemas, we crash with the following error message:

More than twenty 'IServiceProvider' instances have been created for internal use by Entity Framework. This is commonly caused by injection of a new singleton service instance into every DbContext instance. For example, calling UseLoggerFactory passing in a new instance each time--see https://go.microsoft.com/fwlink/?linkid=869049 for more details. Consider reviewing calls on 'DbContextOptionsBuilder' that may require new service providers to be built.

Warning CoreEventId.ManyServiceProvidersCreatedWarning

Our product supports Oracle, MSSQL and Postgres, the other DB types do not exhibit this behavior.

After investigating this issue, we found that calling the UseOracle method on the DbContextOptionsBuilder adds a Devart extension object to the Options.Extensions enumerable. This object contains the connection string, and we suspect that due to this extra object, a new service provider entry is generated in the ServiceProviderCache, which eventually leads to this error.
Please see this:
https://github.com/dotnet/efcore/blob/m ... che.cs#L70

We are not sure whether it's a problem with the Devart data provider or something we are doing wrong.
If you believe we can do something on our side to resolve this, then please let us know, if not, then we would appreciate a fix for this problem.

Re: "More than twenty 'IServiceProvider' instances" error with multitenancy

Posted: Tue 16 Jun 2020 20:26
by Shalex
Try turning off the warning. Refer to https://github.com/dotnet/efcore/issues/16369.

Re: "More than twenty 'IServiceProvider' instances" error with multitenancy

Posted: Wed 17 Jun 2020 10:22
by TheCoolest
Thanks, we did this for now.
But can we expect a fix for this down the line, or are there no plans to change this behavior?

Re: "More than twenty 'IServiceProvider' instances" error with multitenancy

Posted: Sat 04 Jul 2020 14:54
by Shalex
Microsoft.EntityFrameworkCore.SqlServer supports SQL Server 2012 onwards.

Basing on release notes, we suppose that Npgsql.EntityFrameworkCore.PostgreSQL considers a connection to be established to the latest version of PostgreSQL until SetPostgresVersion is set explicitly.

dotConnect for Oracle supports EF Core with a wide line of products (Oracle Database 9.2, 10g, 11g, 12с, 18с, 19с) and the provider behavior (internal services) depends on Oracle version connected to.