From the course: Building and Securing RESTful APIs in ASP.NET Core

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Load data from configuration

Load data from configuration - ASP.NET Core Tutorial

From the course: Building and Securing RESTful APIs in ASP.NET Core

Start my 1-month free trial

Load data from configuration

- [Instructor] You can use the ASP.NET Core configuration pattern to easily load data from a configuration file at run time. This is a useful way to load application settings or other small bits of information that don't need to be stored in your database. ASP.NET Core is already set up to read the appsettings.json file at startup. I'll paste in some json elements I copied to my clipboard. You can find this code in the course exercise files. You'll notice how these json properties correspond exactly to the HotelInfo class I created earlier. In the startup class, we can pull this data out of configuration, and use it to populate an instance of HotelInfo. We'll do this in ConfigureServices. I'll put this at the top, but it could go anywhere inside of ConfigureServices. We need to do services.configure, and then an instance of HotelInfo, or the HotelInfo type. We'll pull this out of the models name space. And we'll say that we wantna populate it from configuration.getsection, and the…

Contents