Open douglasg14b opened 8 months ago
@douglasg14b the general idea seems to be covered in the basic usage docs:
You typically build a single data source, and then use that instance throughout your application
However, it's true that lots of people have run into this problem.
I think a better way here is to add a sample in the basic usage page specifically for DI with AddDbContext, plus a warning there. Then, from the various plugin pages, we can link to the part of the basic usage page. What do you think?
@roji The quote covers this only after one is knowledgeable about the problem IMHO. This is an unexpected side effect that violates that "rule", but not in a way that is obvious or intentional.
Which is why the suggested warning to avoid the pitfall.
We got hung up on this one for quite a while, it's an easy gotcha to run into if you are setting up
NetTopologySuite
in an existing application that obtains the connection string via DI inside of the configuring callback ofAddDbContext
.Setting up the data source inside of the
OnConfiguring
callback causes the dependencies of theDbContextOptions
to be different every time, causing a newServiceProvider
to be made for eachDbContext
which will eventually warn/error with theLogManyServiceProvidersCreated
error in EF Core.Please advise preferred verbiage and location.