doc icon indicating copy to clipboard operation
doc copied to clipboard

Add warning for data source gotcha in NetTopologySuite docs

Open douglasg14b opened this issue 2 years ago • 2 comments

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 of AddDbContext.

Setting up the data source inside of the OnConfiguring callback causes the dependencies of the DbContextOptions to be different every time, causing a new ServiceProvider to be made for each DbContext which will eventually warn/error with the LogManyServiceProvidersCreated error in EF Core.

Please advise preferred verbiage and location.

douglasg14b avatar Dec 29 '23 04:12 douglasg14b

@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 avatar Dec 29 '23 13:12 roji

@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.

douglasg14b avatar May 08 '24 19:05 douglasg14b