Know About ASP.NET Core Project Structure
If you have created ASP.net core web application using VS 2017, you must have noticed the project structure changes and new folders that is quit different than ASP.net MVC Application.
In this article we will quickly walk through the project structure for ASP.net core and explain each component
Let’s get started by creating a new ASP.net core application. Launch VS 2017, select File from the top Menu and click New-> Project
Select ASP.NET Core Web Application from the Project Template window (Refer below screenshot). Enter the Project name, select the directory and click OK button
Once you click on OK button, below dialog box will be displayed to select the framework and version along with the type of Project to be developed
Select .Net Core & ASP.net Core 2.1 & Above and Web Application (Model-View-Controller) project type. Make sure your “Configure for HTTPS” checkbox is un-checked and click OK
You will see the following project structure and folder that is obvisiouly very different than normal ASP.net MVC Application.
Let’s dive into each component of the project structure created
As the name implies, the connected services is used to consume service that will be consumed in application. It can also be used to connect /consume MS Azure cloud based services. To keep it more simple, the connected services is similar to Add Reference that is available in ASP.net & ASP.net MVC Application
Packages and Services required to run and support the Core services of application. The dependencies primarily include the following packages by default
The properties folder includes the launchSetting.json file that provides the option to set default debug setting. Refer below the content of launchSetting.json
You can also access the same setting mentioned in launchSetting.json by right clicking on main Project name -> Property-> Debug.
This is the root web folder provided by the ASP.net core project. The folder is provided to store the static files that can be accessed by relative path in your application.
In the previous version of Asp.net application, you could create your own folder and save the relevant static files and access it however with ASP.net core, you can access static files only if it is placed in wwwroot folder. This is something one need to be aware of.
Static files includes
You may rename the folder as per your requirement and make the necessary changes in the relevant files (program.cs)
Controllers / Models / Views
No change done to the core folder structure pertaining to Controllers/ Models & Views. These folders are created automatically in Asp.net core and in the previous version of dot net too. All three folders support MVC pattern of web application development.
Appsettings.json AND Appsettings.Development.json
In ASP.net core we don’t have our most favourite file that we were using it since its beginning yes you guessed it right the “Web.Config” file.
Instead of Web.Config file , we now have appsettings.json and appsettings.Development.json. Both are similar and you can keep only appsettings.json however in Asp.net core they have given provision to manage your application setting , connection strings and any application specific custom entries based on different environement.
So can manage appsetting.json separately for Dev, Staging & Production environment .
The Program.cs contains the routine to call and initiate the code written in Startup.cs file. Basically Program.cs is the entry point once the application is launched.
ASP.net core has intensively used Dependency Injection (DI). Now we won’t go deep into the details of Dependency Injection (DI) however to cut short the topic DI offers many like lousely coupled design pattern, advantage in Unit Testing i.e. can be independently tested, maintainability of code, reducing the dependency between class and many more features. We will surely publish article on DI and how to implement in Dot-Net.
The Startup.cs offers following method already included by VS 2017
Method used to register all your application dependent services for Dependency Injection (DI). Once you register your classes, the in-built Inversion-Of-Control (IoC) core classes will make it available throughout the Application.
The Configure method will manage the routing behaviour of your Https request in your application.
By default, MVC application routes the request to Index Method in the Home controller. One can definitely change the default routing behaviour in Configure class.
This brings to the end of the Article. I am sure you now have a fair idea on the new project structure provided by ASP.NET Core.
So please stay tuned and do subscribe our newsletters for more insights on ASP.net core and other technology articles
Thanks for visiting DigitalTechJoint.com !!!!