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

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Oracle
Post Reply
TheCoolest
Posts: 22
Joined: Tue 24 Mar 2020 11:02

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

Post by TheCoolest » Tue 09 Jun 2020 07:56

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.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

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

Post by Shalex » Tue 16 Jun 2020 20:26

Try turning off the warning. Refer to https://github.com/dotnet/efcore/issues/16369.

TheCoolest
Posts: 22
Joined: Tue 24 Mar 2020 11:02

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

Post by TheCoolest » Wed 17 Jun 2020 10:22

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?

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

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

Post by Shalex » Sat 04 Jul 2020 14:54

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.

Post Reply