I want to create an ASP.NET Core web application with EF Core for multiple customers on a central server. Each customer should have its own database which gets filled by reading data from measuring devices that belong to the customer.
I found solutions which suggest to create multiple database contexts. The problem with this is that it is not scalable. I don't know the number of customers/databases in advance. Could be 10, could be 100.
Another solution could be to create separate applications in IIS (let's for simplicity only talk about Windows and IIS). Each application would have its own path and its own appsettings.json which specifies the database connection string. The problem with this is that it would take lots of disk space to duplicate the (self-contained) application and a lot of maintenance work.
Questions:
1) is there a way to create a list of database contexts dynamically, given multiple connection strings in my appsettings.json?
2) is there a way to keep only one physical installation in IIS but have multiple sites that each start the application with a different appsettings.json or maybe a start parameter that tells the app which connection string to use from appsettings.json?
3) is there a completely different and better way to achieve it?
DbContextOptions
configure the correct connection string per request. Or put the logic inside the db context (ugh though) by overridingOnConfiguring
.