Wednesday 24 August 2016

ASP.NET Core 1.0 MVC Project Structure Overview

Let’s discuss structure of ASP.NET Core MVC Web Application Project. We are going to use project created in our last discussion Welcome to ASP.NET Core 1.0 MVC. We have following major areas:
  • Properties
  • References
  • wwwroot
  • Dependencies
  • Controllers
  • Views
  • Program.cs
  • Startup.cs
  • Configuration Files



Properties

Properties section contains launchSettings.json file which has project settings. Although it can be edited directly, yet it is generally edited by other interfaces like project properties.

References

References section contains all DLL references added to project. Visual Studio 2015 shows added references in groups. For this template, Visual Studio adds .NET Core Application related DLLs.


We can add new references directly or through NuGet Packages.
  • To add reference from other project of same solution, Open Reference Manger Screen from Context Menu of Project References >> Add References. And then on Reference Manager Screen >> Projects >> Solution >> Select Project Name.
  • To add reference from existing DLLs, Open Reference Manger Screen from Context Menu of Project References >> Add References. And then on Reference Manager Screen >> Assemblies >> Browse >> Select Required Assemblies to be added.
  • To add references from NuGet, Open NuGet Manger Screen from Context Menu of Project References >> Manage NuGet Packages. And then on NuGet Manager Screen >> Browse >> Search and Install Required Assemblies to be added.
  • Open Package Manger Console through Tools >> NuGet Packet Manger >> Package Manger Console and run install command "Install-Package FullPackageName".

wwwroot

wwwroot is a special folder which contains all the static resources like css, images, JavaScript and included libraries. Visual Studio Template uses wwwroot name by default, but we can change it as per requirements.



Dependencies

Dependencies section contains list of third part dependencies added to project through Bower. By default this template adds: bootstrap, jquery, jquery-validation and jquery-validation-unobtrusive.


We can add new bower through Manage Bower Packages.
  • To add new bower Open Manage Bower Packages Screen from Context Menu of Project Bower >> Manage Bower Packages. And then on Manage Bower Packages Screen >> Browse >> Search and Install Required Packages to be added.

Controllers

Controllers folder contains controllers added to application. It is not necessary to add controllers to this folder or to create this folder, but it is one of practices to add controllers to this folder or its subfolders. This templates add HomeController by default with Index, About and Contact action methods.


Views

Views folder contains views in 3 categories:
  • Controller Views
  • Shared Views
  • Special Views

Controller Views

All the views related to a controller have views in a folder named to that controller. This example Home folder contains views for each action method of HomeController.

Shared Views

Shared views folder contains: _Layout and Error view. _Layout view contains layout of application and in term of ASP.NET it replaces Master Page. Error view contains the implementation of error page which is displayed to end user in case of any error.

Special Views

While there are 2 special views in this template: _ViewImports and _ViewStart. _ViewImports contains the list of imports for all views. And ViewStart contains generic page initializations like layout globally.



Program.cs

Program.cs contains Main method, which is starting point of application. It initializes WebHostBuilder instance and starts the host environment. We can set web server related configurations in this area. We will have complete detailed discussion on this item separately.


Startup.cs

Startup.cs contains main implementation for Environment Startup. This class not only initialize basic environment configurations and request pipeline but also other features like logging, error page and routing. We will have complete detailed discussion on this item separately.


Configuration Files

This template creates different configuration files of .config and .json type at root of project:
  • appsettings.json 
  • bundleconfig.json 
  • project.json
  • web.config
These files contains application settings, configurations related to bundling and minification and project settings. We can also use ini files, environment variables, command line arguments and even custom configuration provider. We will have complete detailed discussion on this item separately.




1 comment:

  1. Other available promos include reload bonuses, a sports activities welcome promo, and a poker bonus. There’s a $3,750 crypto casino bonus up for grabs for those who|for many who|for people who} deposit utilizing crypto. Bovada has a superb provide model spanking new|for brand new} gamers, especially those who use cryptocurrency. For those who are into slots or poker, relaxation of|the remainder of} the casino foyer 점보카지노 can also be|can be} not too shabby. One factor we like about this bonus is that it’s divided into four parts.

    ReplyDelete