today i'm learning the new ASP.net core API 3.1 and i want to transfert my old websites from MVC4 to web API. All work good except one thing. The database connection. In my old website, i've a database for each clients (10/15 DB's) and i use main database to get the client databse after connection.
Here is my code for my Old DBContext (for local test here)
public DBContext(string database)
: base("Data Source=***SQLServer***;Initial Catalog=" + database + ";Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False"){}
I get the database name string from the AdminDatabase in the DAL and pass it to DBContext.
But now with the services for connections, i don't understand how to do that. If i place the connection string in appsettings json, i can't pass database name parameter.
I try to specify the connection string directly in the startup.cs file but i've seen somewhere it's not secure to do that, the appsetting.json keep connection strings secret...
If you have idea, let me know friends ;)
dynamicaly? If you want to connect to multiple database, you can create multiple dbcontext to connect to corresepond connection string in appsetting.json, you can refer to :learn.microsoft.com/en-us/aspnet/core/data/ef-mvc/…