& Lt; ASP. NET Boilerplate document & gt; 1.2 multilayer structure, asp. netboilerplate

Source: Internet
Author: User

<ASP. NET Boilerplate document> 1.2 multilayer structure, asp. netboilerplate

  • Introduction
  • ABP Structure
  • Multi-Layer
  • Other layer (General)
    • Domain (Core) Layer
    • Application Layer
    • Base Layer
    • Web & Presentation Layer
  • Others
  • Summary


Introduction

The layering of an application code library is a widely accepted technology used to reduce complexity and improve code reusability. According to the concept of DDD, there are four basic layers in DDD:

  • Presentation Layer: provides an interface for users. Use the application layer to complete user interaction.
  • Application Layer: media of the presentation layer and domain layer. Coordinates service objects to execute specified application tasks.
  • Domain Layer: Includes Business Objects and business rules. Is the core of the entire application.
  • Base Layer: provides general technologies that support higher levels. A typical example of a base layer is to use the ORM framework to achieve the warehousing of interaction with the database, or to implement mail sending.

You can also add layers as needed, for example:

  • Distributed service layer: publish application features for remote clients. Such as Asp.net web API and WCF.

These are the general layers of the domain-centered architecture. Implementation may be slightly different.

 

ABP Architecture

An overview of layers and structures is as follows:

Layers
Presentation View Models (Javascript), Views (HTML/CSS), Localization, Navigation, configurations
Web Web API Controllers, MVC Controllers, OData, ASP. NET Core
Application Application Services, DTOs, DTO Mappers, Authorization, Session, Audit Logging
Domain (Core) Entities, Value Objects, Repositories, Domain Services, Unit of Work, Domain Events
Infrastructure ORM (EntityFramework, nhibations), DB Migrations, Background Jobs
Others (common)

A simple hierarchical application that contains five projects:

One layer can be implemented into one or more sets. In a large project, it may be more appropriate to create multiple assemblies for third-party dependencies (like the EntityFramework here) so that each layer has its own Context.

 

Domain (Core) Layer

The domain layer must implement all business rules.

Entity: displays operations on data and domain businesses. Generally, they are mapped to database tables.

Warehousing: similar to object sets, used to obtain and persist entities to data sources (databases ). The domain layer defines warehousing, but does not implement them. It is implemented by the Base layer.

Domain events: define specific events in the domain and trigger and process them. Domain services use entities (and other domain objects) to implement business rules that do not belong to a specific entity.

Unit of work: it is a design pattern for managing database connections and transactions, Tracking Entity changes and saving changes to data storage. The domain layer defines it, but it is implemented by the Base layer.

This layer should be as independent as possible from third-party class libraries.

 

Application Layer

The application layer contains the application services used for the presentation layer. An application service method can receive a DTO (data transmission object) as the input, use this input to perform operations at the domain layer, and return another DTO as needed. It should not receive or return entities. An application service method is considered as a work unit. User input verification is also implemented at this layer. We recommend that you use tools like the AutoMapper library to map entities and DTO. This layer also contains Sessions of the current user information ).

 

Base Layer

When the domain layer defines warehousing, work units, and other service interfaces, the basic layer implements these products. Use ORM tools (such as nhib.pdf or EntityFramework) to implement warehousing. These two ORM frameworks provide the base classes. The base layer abstracts the dependency on third-party libraries from other layers. You can also use data migration in this layer.

Apart from data access, we may need to abstract the service provider. For example, I may use the service provided by the service provider to send short messages. We can define an interface at the domain layer or application layer to abstract it, then we implement it in this layer.

 

Web & Presentation Layer

The Web layer is implemented using Asp.net, Web API, and Asp.net Core. Both methods can be implemented in SPA or MPA, and the launch template also supports these two methods.

All resources in a SPA are loaded only once (or the core resources are loaded in advance and other resources are loaded in time when needed) to the client (browser). AJAX is used for subsequent interactions with the server, after obtaining data from the server, the Html code is created on the client. The entire page is no longer refreshed, and the view is only swapped out when needed. There are many Javascript SPA frameworks such as Angularjs, Backbonejs, and Emberjs. You can use either of these methods, but it is easier to use Angular using examples and some help mechanisms.

In a MPA, the client sends a request to the server. The server code (usually Asp.net MVC Controller) obtains data from the database and creates HTML in the Razor rendering view. The created page is sent back to the client for display. The entire page is refreshed for each new page. However, the client can also optimize the experience through additional AJAX requests.

SPA and MPA involve completely different structures. The perfect choice for a management panel is SPA. In addition, it is best for a blog to choose MPA, because it is more conducive to discovery by search engines. Even so, the SPA can be discovered by search engines through tools. Of course, these are just common practices.

SignalR is a perfect tool for pushing notifications from the server to the client. It provides rich and real-time user experience.

There are many Javascript classes and frameworks on the client. Jquery is the most popular and has thousands of free plug-ins. Of course, there are still many tools/frameworks that make it better work with HTML and CSS. For example, Twitter's Bootstrap is a very popular HTML/CSS framework.

ABC provides basic services and automatically creates a Web API layer from your application service. Javascript can easily use them. In addition, it provides basic services to manage Application menus, localization, and language switching. It also contains a simple but unified Javascript API to simplify the display of system information and notifications.

The ABP automatically handles exceptions on the server and returns a corresponding response to the client.

 

Others

ABP uses the Castle Windsor framework to support dependency injection. At the same time, Log4Net is used to record logs for the client. However, you can easily switch the log class library by using Castle's abstract log base without changing the code.

 

Summary

ABC coordinates some of the best frameworks/class libraries with its own classes and systems to provide a better basic service, facilitating the use of multi-layer structures to create a Web application. Templates provided at the same time make it easier to provide multi-layer solutions for your applications.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.