"More than twenty 'IServiceProvider' instances" error with multitenancy
Posted: 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.
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.