ASP.NET CORE Project Structure Overview

In this tutorials will discuss and understand.

        • Crearte ASP.NET Core First Application.
        • ASP.NET Core Project structure overview.

Creating First ASP.NET Core Web Application

We are using Visual Studio 2019 To create a new ASP.NET Core Project, Open Visual Studio 2019. And then click on the Create a new project box as shown in the below snap.

Once you click on the Create a new project box, it will open the “Create a new project” window. This window includes different .NET Core 3.1 application templates. Here we will create a simple web application, so select the ASP.NET Core Web Application template and click on the Next button as shown in the below snap.

Once you click on the Create button, it will create a new ASP.NET Core Web Project in Visual Studio 2019. Wait for some time till Visual Studio restores the packages in the project. The restoring process means Visual Studio will automatically add, update or delete configured dependencies as NuGet packages in the project.

The project will be created with the following file and folder structure in Visual Studio 2019.

Connected Services

It is use to automate the multiple steps necessary to connect a project to an external service (like Azure Storage or Application Insights) etc.

Dependencies

In ASP.NET Core, Dependencies is the place where the necessary dll.s for the application are stored. it includes analyzers, packages and frameworks.

Properties

Inside the Properties, you will see a file called launchSettings.json which describes how a project can be launched. Each profile defines how to run your project when you click on the “Run” button in Visual Studio. It describes the command to run, whether the browser should be opened, which environment variables should be set. Most of the properties there affect the compile- and debug-time behavior of your project.

wwwroot

This is the folder which contains all the static files of your web application: CSS files, JavaScript files, images, and icons. All Static content is hosted in the wwwroot folder.

Controller :This is folder where we adding our controller that are requires for our application.

Models: This is folder where we add all our model which nothing but the c# classes.

Views: This is folder where add all our views which use for represntation.

appsettings.json

This is a JSON file that stores the application’s settings or  configurations. it is used to store information such as connection strings or application specific settings and these are stored in the JSON format as the file extension suggests. Its smilar to the web.config if you familiar with asp.net mvc.

Program.cs

Program.cs is the main entry point for the application. The only purpose of this method is to define the host and then pass the control to the Startup class.

Startup.cs

its includes Configure and ConfigureServices methods and its performing below tasks.

      • It used to performs all initialization tasks (setting application-wide constants, DB seeding, migrations, etc.).
      • It used to registers all services used in this project in the DI (dependency injection) container.
      • It use to defines the middleware pipeline of your web-application.

ConfigureServices: This the method is a place where you can register your dependent classes with the built-in IoC container. After registering the dependent class, it can be used anywhere in the application. You just need to include it in the parameter of the constructor of a class where you want to use it. The IoC container will inject it automatically.

Configure: This method is used to specify how to configure HTTP requests pipleline. The request pipeline is configured by adding middleware components to an IApplicationBuilder instance. IApplicationBuilder is available to the Configure method, but it isn’t registered in the service container. Hosting creates an IApplicationBuilder and passes it directly to the Configure method

You can watch our video for the tutorial with step by step explanation