December 2019
Intermediate to advanced
510 pages
11h 33m
English
As discussed in Chapter 2, Overview of ASP.NET Core, the appsettings.json file usually contains the application settings. The connection strings are typically stored in that file. Therefore, that kind of approach makes our service more reusable and configurable, especially when it is already running in a staging or production environment. Let's move the connection string from the AddCatalogContext method to the appsettings.json file in the following way:
{... "DataSource": { "ConnectionString": "Server=localhost,1433;Initial Catalog=Store;User Id=catalog_srv;Password=P@ssw0rd" }}
In this way, we can read the connection string and pass it to AddCatalogContext as a parameter using the following syntax:
..public ...Read now
Unlock full access