Introducing the DDD concept
Eric Evans's "Domain-driven design field Drive", referred to as DDD, is a set of object-oriented modeling methods for integrated software system analysis and design, or one that can be called an MDD model-driven approach, differentiated from the MDA model-driven architecture. It is an analytic design modeling method, it advocates the unified language, proposed the entity and the value object as well as the aggregation root and so on the concept, with the help of ddd we can in the structure to clarify the demand domain model.
past system Analysis and system design are separate, as our national "system analyst" and "system Designer" two titles examination, such fragmented results lead to the results of demand analysis can not be directly programmed programming, and can be programmed to run the code is distorted requirements, Cause customers to run the software only to discover that many features are not what they want, and the software can not quickly follow the changes in demand.
Objective
In order to reduce complexity and improve the reusability of code, adopting a layered architecture is a widely accepted technique. To achieve a layered architecture, ABP follows the principles of DDD (domain driven design) and is divided into four levels:
- presentation Layer (Presentation): Provides a user interface for user interaction.
- Application Layer (application): Performs the coordination between the presentation layer and the domain layer, and coordinates the business objects to perform the tasks of the specific application. It does not contain business logic.
- domain layer (domain): Includes business objects and business rules, which are the core layers of an application.
- infrastructure Layer (Infrastructure): Provides generic technology to support higher tiers. For example, the infrastructure layer Warehousing (Repository) can be used to achieve database interaction through ORM.
Depending on your actual needs, there may be additional layers added. For example:
- Distributed services Layer (distributed service): Used to expose application interfaces for remote client invocation. For example, through the ASP. NET Web API and WCF.
These are common domain-centric hierarchical architectures. There may be subtle differences in the implementation of different projects.
Architecture of ABP
a simple solution that roughly consists of 5 projects:
Each layer can be implemented with one or more assemblies.
Domain Layer (domain)
The domain layer is the business layer, the core of a project, and all business rules should be implemented at the domain level.
entity entities represent the data and operations of the business domain, in practice, by mapping them to database tables.
warehousing (Repository) warehousing is used to manipulate databases for data access. Warehousing interfaces are defined in the domain layer, and the implementation class for warehousing should be written on the infrastructure layer.
Domain Service When a business rule is processed that spans two (and more) entities, it should be written in the domain service method.
Domain events can trigger domain events when certain situations occur in the domain layer, and they are captured and processed in the appropriate places.
The unit of work unit is a design pattern that maintains a list of business objects that have been modified, such as additions, deletions, and updates. It is responsible for coordinating the persistence of these business objects and concurrency issues.
Application Layer (application)
The application layer provides some application service (application services) methods for presentation layer invocation. An application service method receives a DTO (data transfer object) as an input parameter, performs a specific domain-level operation using this input parameter, and can return another dto as needed. In the presentation layer to the domain layer, the entity object should not be received or returned, and the DTO mapping should be done. An application service method is generally considered a unit of work. Validation of user input parameters should also be implemented at the application level. ABP provides an infrastructure that makes it easy to implement validation of input parameters. It is recommended to use a tool like AutoMapper to map the entity to the DTO.
Infrastructure Layer (Infrastructure)
When warehousing interfaces are defined in the domain layer, these interfaces should be implemented in the infrastructure layer. You can use ORM tools, such as EntityFramework or NHibernate. The base class for ABP already provides support for both ORM tools. Database migrations are also used in this layer.
Web and Presentation layer (Web & Presentation)
The Web tier is implemented using ASP. NET MVC and Web APIs. Can be used for multi-page applications (MPA) and single-page applications (SPA), respectively. In the spa, all resources are loaded once into the client browser (or the core resources are loaded first, other resources are lazy to load), and then the server-side Webapi interface is fetched via AJAX, which generates HTML code based on the data. Does not refresh the entire page. Now there are many spa JS frameworks, such as: AngularJs, Durandaljs, Backbonejs, Emberjs. The ABP can use any similar front-end framework, but the ABP provides some help classes that make it easier to use ANGULARJS and Durandaljs.
In a classic multi-page application (MPA), the client makes a request to the server, the server-side code (the ASP. NET MVC Controller) obtains the data from the database, and uses the Razor view to generate the HTML. These are generated after the HTML page is sent back to the client display. Each new page will be refreshed with a full page.
Spas and MPA involve a completely different architecture, as well as a different application scenario. A management background suitable for spa, blog is more suitable for MPA, because it is more conducive to the search engine crawl.
SIGNALR is the perfect tool for sending push notifications from the server to the client. It gives users a rich, real-time experience.
There are already many client-side JavaScript frameworks or libraries, and jquery is one of the most popular, and it has thousands of free plugins. Using bootstrap makes it easier for us to do the work of writing HTML and CSS.
The ABP also implements code functions that automatically create JavaScript based on the Web API interface to simplify JS's invocation of the Web API. And the server side of the menu, language, settings, etc. generated to the JS side. (But in my own project, I turned off these auto-generation functions because the necessity was not very large, and these would have more impact on performance).
The ABP automatically handles the exception returned by the server side and prompts the user with a friendly interface.
Other
The ABP uses Castle Windsor to provide dependency injection functionality for the entire program framework. Use the Log4net logging component to provide other layers of calls to log records.
(turn) DDD-based modern ASP. NET Development Framework--ABP layered architecture