The new configuration pattern in ASP.NET Core makes it easy to load static data from JSON or other configuration sources. Nate shows you how to populate a class with data from configuration.
- [Narrator] 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. If you open the startup.cs file you can see this in the constructor. By default, the application looks for appsettings.json and loads those settings into memory when the application starts up. We can add our own properties to the appsettings.json file and then pull them out in code.
I'll paste in some information I already created into appsettings.json. All of the settings in appsettings.json are just json objects and elements. You'll notice that these elements correspond exactly to the class I created previously. Now that I've put some data into appsettings.json I can pull it out in my code. In the configure services method I can say services.configure and then the type HotelInfo, which is the class I created earlier, and specify that as a source for data for the HotelInfo class I'm going to use configuration.GetSection which is the root element of the data I added to appsettings.json.
This line does a couple of things. It pulls the properties from the info section out of the appsettings.json file and creates a new instance of HotelInfo with those values. Then it wraps that instance in an interface called IOptions and puts that into the service container. Once it's in the service container it can be injected into controllers. Next we'll create a new controller that will return this data as a restful resource.
- REST vs. RPC
- Using HTTP methods (aka verbs)
- Returning JSON
- Creating a new API project
- Building a root controller
- Routing to controllers with templates
- Requiring HTTPS for security
- Creating resources and data models
- Returning data and resources from a controller
- Representing links (HREFs)
- Representing collections
- Sorting and searching collections
- Creating forms
- Caching and compression
- Authentication and authorization for RESTful APIs
Skill Level Intermediate
Deploying ASP.NET Core Applications (2017)with Nate Barbettini57m 57s Intermediate
1. REST API Concepts
2. Building a Basic API
3. Securing the API
4. Representing Resources
5. Representing Links
6. Representing Collections
7. Sorting Collections
8. Searching Collections
9. Forms and Modifying Data
10. Caching and Compression
11. Authentication and Authorization
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.