Please enable JavaScript.
Coggle requires JavaScript to display documents.
ASP.Net Core MVC (Project Items (/Areas
Areas are a way of partitioning a…
ASP.Net Core MVC
Project Items
-
-
/Components
This is where view component classes, which are used to display self-contained features such as shopping carts, are defined.
/Controllers
This is where you put your controller classes. This is a convention. You can put your controller classes anywhere you like because they are all compiled into the same assembly.
-
/Data/Migrations
This is where Entity Framework Core migrations are stored so that databases can be prepared to store the application data.
/Models
This is where you put your view model and domain model classes. This is a convention. You can define your model classes anywhere in the project or in a separate project.
/Views
This directory holds views and partial views, usually grouped together in folders named after the controller with which they are associated.
-
/Views/_ViewImports.cshtml
This file is used to specify the namespaces that will be included in Razor view files.
-
/appsettings.json
This file contains configuration settings that can be tailored for different environments, such as development, testing, and production. The most common uses for this file are to define database server connection strings and logging/debug settings
-
/<project>.csproj
This file contains the configuration for the project, including the NuGet packages that the application requires.
This file is hidden and can be edited only by right-clicking the project item in the Solution Explorer window and selecting the Edit <project>.csproj menu item.
-
-
/wwwroot
This is where you put static content such as CSS files and images. It is also where the Bower package manager installs JavaScript and CSS packages
Compare MVC to
Smart UI Pattern
- One of the most common design patterns
- Windows Forms or ASP.NET Web Forms
- The code that handles the user interface and the business is all mixed together with no separation of concerns at all.
-
Pros
- Ideal for simple projects
- Suited to user interface prototyping
Cons
- Difficult to maintain and extend
- Mixing the domain model and business logic code in with the user interface code leads to duplication.
- It can be almost impossible to add a new feature without breaking an existing one.
- Testing an application can be difficult.
Model-View Architecture
- Pulls out the business logic into a separate domain model.
- The data, processes, and rules are all concentrated in one part of the application
-
Problems
- The UI and the domain model are closely integrated, it can be difficult to perform unit testing on either.
- The model typically contains a mass of data access code and this means that the data model does not contain just the business data, operations, and rules.
Classic Three-Tire Architecture
The three-tier or three-layer pattern separates the persistence code from the domain model and places it in a new component called the data access layer (DAL).
-
- Unit testing is relatively easy.
- Impossible to perform automated unit tests.
- No real separation of concerns.
Model-View-Presenter (MVP) Pattern
The presenter has the same responsibilities as an MVC controller, but it also takes a more direct relationship to a stateful view, directly managing the values displayed in the UI components according to the user’s inputs and actions.
Implementations:
- The passive view implementation, in which the view contains no logic. The view is a container for UI controls that are directly manipulated by the presenter.
- The supervising controller implementation, in which the view may be responsible for some elements of presentation logic, such as data binding, and has been given a reference to a data source from the domain models.
The difference between these two approaches relates to how intelligent the view is. Either way, the presenter is decoupled from the GUI framework, which makes the presenter logic simpler and suitable for unit testing.
Model-View-View Model (MVVM) Pattern
- Models and views have the same roles as they do in MVC.
- the view model is a C# class that exposes both properties for the data to be displayed in the UI and operations on the data that can be invoked from the UI.
Project Templates
Empty
The Empty project template contains the plumbing for ASP.NET Core but doesn’t include the libraries or configuration required for an MVC application.
Web API
The Web API project template includes ASP.NET Core and MVC, with a sample application that demonstrates how to receive and process data requests from clients, using an API controller
Web Application (Model-View-Controller)
The Web Application (Model-View-Controller) project template includes ASP.NET Core and MVC, with a sample application that demonstrates how to generate HTML content.
Angular | React.js | React.js and Redux
The other templates provide initial content suitable for working with single-page application frameworks (Angular and React) and with Razor Pages
C# Features
Null Conditional Operator
- The null conditional operator allows for null values to be detected more elegantly.
Using the Null Conditional Operator
- If p is null, then name will be set to null as well. If p is not null, then name will be set to the value of the p.Name property.
string name = p?.Name;
Chaining the Null Conditional Operator
Combining the Conditional and Coalescing Operators
Automatically Implemented Properties
- This feature allows to define properties without having to implement the get and set bodies.
Using Automatically Implemented Properties
Auto-Implemented Property Initializers
Read-Only Automatically Implemented Properties
-
-
MVC Pattern
-
-
Controller
Process incoming requests, perform operations on the model, and select views to render to the user
-
Should Not
-
Contain logic that creates, stores or manipulates the domain model
Conventions
Classes
- Controller classes have names that end with Controller
Views
- Views go into the folder named /Views/Controllername.
- MVC expects that the default view for an action method should be named after that method.
Layouts
- The naming convention for layouts is to prefix the file with an underscore (_) character.
- Layout files are placed in the /Views/Shared folder.
- layout is applied to all views by default through the /Views/_ViewStart.cshtml file.