Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Patterns

Steve Smith edited this page Nov 29, 2021 · 4 revisions

The eShopOnWeb reference application employs a number of software design patterns which are implemented either in the code itself, or with the assistance of various open source NuGet packages.

MVC

The front end of the application's web project implements the class Model-View-Controller pattern. It includes a number of controllers in its Controllers folder, which work with Views to return rendered HTML to the client, typically a browser. For example, the OrderController class includes an action method that returns a Detail view. The view is in the /Views/Order/Detail.cshtml file, and binds to a model of type OrderViewModel to render specific data within the razor view template.

The sample also demonstrates the use of alternate flavors of the MVC pattern, including Razor Pages and API Endpoints, described in more detail below.

Razor Pages

Razor Pages are an ASP.NET Core feature that reorganizes MVC's controllers, action methods, and views. Instead of having controllers with many often unrelated action methods which in turn were bound to many views in a separate folder structure, Razor Pages replaces views with a page metaphor and uses handlers attached to the page instead of actions. Razor Pages also provide their own strongly typed viewmodel, eliminating the need for a separate folder full of viewmodels in many cases.

API Endpoints

API Endpoints reorganize APIs in much the same way Razor Pages reorganize controllers and views. Instead of having many unrelated endpoints as separate actions in a controller (or Program) class, each web api endpoint is encapsulated in its own class, along with its associated model types. Many .NET developers already use the mediator pattern (below) to achieve organization; API Endpoints eliminates the need to use a mediator and instead works by simply extending the ControllerBase class.

Mediator

Some parts of the application use the mediator design pattern to decouple initiating actions from their implementations. These actions can be in the form of commands that expect a result, or events that have no expected response. The sample uses the MediatR package for its implementation of the pattern, which you will see used in the Web project.

Repository

TBD

Specification

TBD

Guard Clauses

TBD

Entities

TBD

Aggregates

TBD

Resources

TBD

Clone this wiki locally