In my last post, I briefly mentioned config.json in ASP.NET Core. In this post, I am going to drill into configuration and config.json a bit more …

Configuration Source

ASP.NET Core configuration is a lot more flexible - in particular, the way you can have configuration settings coming from different sources. In the following example we are going to get a connection string from config.json.

Firstly, we need to declare a dependency so that we can easily read from config.json:

dependency

Then we wire up config.json in the constructor of Startup.cs:

startup

Reading Configuration Settings

Let’s say we have the following config.json that defines the connection to our database:

config.json

In order to read the connection string we use IConfiguration.Get():

read

   ASP.NET config.json
1.20 GEEK