J
J
John2018-07-12 18:32:23
ASP.NET
John, 2018-07-12 18:32:23

ASP.NET Core: how many configs should there be for different databases and how to distribute them among controllers?

I have an MVC application that takes the database connection settings from appsettings.json. The controller then uses these settings via IConfiguration.
Now I need to make sure that the application can also connect to another database. How to do it right?
1. Should there be a separate route and controller for the new database?
2. Should there be a separate json file that I will feed to the controller from step 1?
Just for information (if it matters): in the frontend it will be a separate tab. Those. on the first tab data from the first database is issued, and on the new second tab - from the second database.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
basrach, 2018-07-15
@basrach

You need two different contexts. Contexts are those classes that inherit from DbContext and abstract access to the database. One for one base, the other for the second base. Accordingly, you will have configs according to the number of databases, i.e. also two.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question