Carl Rippon

Building SPAs

Carl Rippon
BlogBooks / CoursesAbout
This site uses cookies. Click here to find out more

ASP.NET config.json

March 10, 2015
dotnet

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

Notice how you use a colon to get to the nested value in the object graph.

Other Articles

Louis Dejardin explains the reasons for the changes in ASP.NET configuration and this post from Jaspalsinh Chauhan is another great article on this topic.

If you to learn about using React with ASP.NET Core you might find my book useful:

ASP.NET Core 5 and React

ASP.NET Core 5 and React
Find out more

Want more content like this?

Subscribe to receive notifications on new blog posts and courses

Required
© Carl Rippon
Privacy Policy