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.
"More than twenty 'IServiceProvider' instances" error with multitenancy
-
- Posts: 22
- Joined: Tue 24 Mar 2020 11:02
Re: "More than twenty 'IServiceProvider' instances" error with multitenancy
Try turning off the warning. Refer to https://github.com/dotnet/efcore/issues/16369.
-
- Posts: 22
- Joined: Tue 24 Mar 2020 11:02
Re: "More than twenty 'IServiceProvider' instances" error with multitenancy
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?
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
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.
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.