ASP.NET Core MVC Initialization
Explore how to initialize and configure an ASP.NET Core MVC web application. Understand the setup of Program.cs, dependency injection, routing, middleware, and default MVC routes to create scalable websites.
We'll cover the following...
Appropriately enough, we will start by exploring the MVC website’s default initialization and configuration:
Step 1: Open the Program.cs file and note that it uses the top-level program feature (so there is a hidden Program class with a $ method). This file can be divided into four important sections from top to bottom. As we review the sections, we might want to add comments to remind ourselves what each section is used for.
Note: .NET 5 and earlier ASP.NET Core project templates used a
Startupclass to separate these parts into separate methods, but with .NET 6 and later, Microsoft encourages putting everything in a singleProgram.csfile.
Step 2: The first section imports some namespaces, as shown in the following ...