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 - ASP.NET Core Tutorial
From the course: Building and Securing RESTful APIs in ASP.NET Core
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
Create a resource class2m 19s
-
(Locked)
Load data from configuration1m 35s
-
(Locked)
Return data from a controller3m 5s
-
(Locked)
Set up an in-memory database2m 22s
-
(Locked)
Create data model classes1m 44s
-
(Locked)
Seed the database with test data5m
-
(Locked)
Return a resource from a controller4m 47s
-
(Locked)
Move data access to a service4m 39s
-
(Locked)
Map models automatically3m 47s
-
-
-
-
-
-
-
-
-