This section is about the creation of a web api to create and download licenses.
Structure of project
Structure tree of the web api project
The following project is a solution created in NET 5.0 using ASP.NET Web Api.
Startup class
Configure services
All services are injected in this class with dependency injection. So far, the following services are injected:
DbContext: The connection string is provided by the appsettings.json file, there are three: Development, Staging, and Production.
AutoMapper: This service is used to map from one class to another, usually to map dtos.
Controllers Folder
Where the controllers are.
StudioLicenseController is the only controller yet.
Controller
Important things to know:
Route attribute: Indicates the route of the controller. The api is optional but usually, api services have it. The "[controller]" is a standard for the web api framework that indicates the name without the controller, in this case, to access the api will be: "api/StudioLicenses"
Inheriting ControllerBase: As we don't support views we inherit from the ControllerBase instead of the Controller class.
Data Folder
Where the DbContexts are.
Db Context
Every class should derive from DbContext.
Important things to know:
These classes have a required parameter called 'DbContextOptions' that should be passed to the base class.
Each DbSet should have the same name of the table in the database or the connection won't work correctly.
Models Folder
Where the data models are. These classes must have properties with the exact name of the column names in the database so the Entity Framework does its job to link them.
Services Folder
This folder does not exist yet, but it will. It will contain the logic to add a license or update it.