ASP.NET

ASP.NET Core Web API Application Structure

Contents

Here you will learn the structure and importance of the Web API project created with ASP.NET Core 3.1.

Before starting, I recommend you to review the article called Create And Consume ASP.NET Core Web API, where I show you how to create a project.

Project Structure

The following is a default project structure when you create an ASP.NET Core Web API project in Visual Studio.

ASP.NET Core Web Application Project Structure
ASP.NET Core Web Application Project Structure

.csproj File Structure

The .csproj file contains settings such as .NET Frameworks, project files, NuGet packages. It does not create .csproj in ASP.NET Core 1.0, instead the project is managed with .xproj and project.json files.

Right-click the project and select Edit Project File to access the .csproj file.

.csproj file structure
.csproj structure

Dependencies

Dependencies includes all installed server-side NuGet packages, Analyzers and Frameworks. To add NuGet packages, right-click the project and select Manage NuGet Packages.

Properties

Properties contains the file launchSettings.json, which contains Visual Studio profiles of debug settings.

launchSettings.json structure
launchSettings.json structure

Program.cs

The Main method in the Program.cs file in the project is the starting point of the project. The most basic components needed by the application are connected to the WebHostBuilder object created here, and the application is run over this object.

Startup class is the second method that runs after the main method. While the basic components are determined in the Main method, the middleware and service components needed in the next step will be determined in the class named Startup. The WebHostBuilder object determines this class with the UseStartup() method.

Program.cs class
Program.cs structure

Startup.cs

There are two important methods in this class; Configure and ConfigureServices.

Middleware components are determined in the Configure method. They structures that we can liken to HttpModules in ASP.NET. They are structures that take place in the application pipeline and run on every request-response.

In the ConfigureServices method, service components are registered to the container object and are used in different parts of the application (for example, Controller classes).

Startup.cs class
Startup.cs structure

Conclusion

In this article, I tried to explain the structure of a project created with ASP.NET Core 3.1. The titles here should be discussed in detail.

Related Posts

Serkan

Software Engineer. Problem solver. Music practitioner. Thinker. Industrious.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button