DDD (Domain Driven Design) architecture

First, why should stratified

Layered architecture is the originator of all architecture, layered effect is isolated, however, we sometimes have a misunderstanding, that is, the layer assembly and association, it is such a simple three-tier system in your solution, general there will be three assembly project: XXUI.dll, XXBLL.dll and XXDAL.dll, then these three assemblies as a layer, this is not a big, complicated project but when, if it is in this way, then your program will focus on the growing number of folders, the assembly will be growing. When your vision out of the concept of an assembly, you will find, not just layer and the corresponding assembly, and also the solution folder, or the corresponding entire solution, or even a layer corresponds to a system.

Layered object thought that in order to "high cohesion and low coupling".

Second, Microsoft's classic three-tier architecture

.Net knows any of Microsoft's three-tier, three-tier architecture is divided into the business layer interface (User Interface layer), the business logic (Business Logic Layer), data access layer (Data access layer). As shown below

The role of each layer:

Interface layer (UI): The main representation WEB way, it can also be expressed as WINFORM way; if the logic layer quite powerful and perfect, regardless of how to define and change the presentation layer, logic layer can improve the delivery of services. Mainly accepts the user's request, and return data.

Business Logic Layer (BLL): mainly operation of specific problems, can also be operated in pairs to understand the data layer, business logic processing of the data, if the data layer is a building block, logic layer that is to build on these building blocks.

Data Access Layer (DAL): mainly to see there is no data layer comprising a logic processing, in fact, its function is mainly to complete each individual operation of the data file. And do you need other operations.

In the eyes of developers, a hierarchical business system only, so the log will record, rights management, database persistence on the technical architecture, messaging services, etc., some can be separated as much as possible to separate, then put them things combined, it would help the system level, they carry the entire business system.

Three-tier architecture is typical transaction script logical structure, a complex business in BBL described the method body from start to finish, handle highly complex business powerless! ! !

All .NET programmers are estimated from this classic three-tier architecture came to be step by step.

Three, DDD classic stratified

DDD: Domain-Driven Design

TDD: Test-driven development is 

POEAA: Enterprise Application Architecture

DDD core idea is controlled by the business in the form of solutions to problems from a database-centric model for the transition to center field 

The following chart is a classic hierarchical me "model-driven design and practical areas" in the book shot down, he fully interpretation of DDD.

The concept of layers:

Presentation Layer (Presentation Layer): a user interface layer in the figure includes a user interface layer, a data display and user input.

The application layer (Application Layer): the application layer defines the business function system, and directing the field of the art the object layer to implement these functions.

FIELD layer (Domain Layer): the core layer, to achieve all the business logic.

Infrastructure layer (Infrastructure Layer): to provide basic services the entire business system.

The layers were classes at compile time dependencies below (this is a very short dwarfish FIG poor):

High-level modules should not depend on the underlying module, both of which should depend on abstractions

Abstract should not depend on the details, the details should depend on the abstract.

Four, ABP stratified

The festival FirstABP solution:

ABP detailed stratification:

We look at all mean from top to bottom:

Presentation layer

Presentation:

View Models (Javascript):=

Views (HTML/CSS):=

Localization, Navigation, Notifications: multi-language, menu, notice

web:

Web API Controllers: webapi Interface

MVC Controllers, OData: I do not know what is OData

Application layer (Application)

Application Services: Application Service

DTOs: Data Transfer Object

DTO Mappers: AutoMapper mapping between the entity and DTO

Authorization: Parameter Validation

Session:

Audit Logging: Audit Log

应用层提供一些应用服务(Application Services)方法供展现层调用。一个应用服务方法接收一个DTO(数据传输对象)作为输入参数,使用这个输入参数执行特定的领域层操作,并根据需要可返回另一个DTO。在展现层到领域层之间,不应该接收或返回实体(Entity)对象,应该进行DTO映射。一个应用服务方法通常被认为是一个工作单元(Unit of Work)。用户输入参数的验证工作也应该在应用层实现。ABP提供了一个基础架构让我们很容易地实现输入参数有效性验证。建议使用一种像AutoMapper这样的工具来进行实体与DTO之间的映射。

领域层(Domain(Core))

Entities:实体,领域对象,代表业务领域的数据和操作

value objects:实体模型

Repositories:仓储,用来操作数据库进行数据存取。仓储接口在领域层定义,而仓储的实现类应该写在基础设施层。

Domain Services:领域服务,当处理的业务规则跨越两个(及以上)实体时,应该写在领域服务方法里面。

Domain Event:领域事件,在领域层某些特定情况发生时可以触发领域事件,并且在相应地方捕获并处理它们。

Unit of Work:工作单元,一种设计模式,用于维护一个由已经被修改(如增加、删除和更新等)的业务对象组成的列表。它负责协调这些业务对象的持久化工作及并发问题。

基础设施(Infrastructure)

ORM (EntityFramework, NHibernate):ORM框架,ABP提供了EF和NHibernate支持

DB Migrations:EF Code First创建数据库用的

Background Jobs:作业调度和自动任务,(类似Quartz.NET)

补充(单页面应用和多页面应用)

在单页面应用中(SPA),所有的资源都会一次性加载到客户端(或者只加载核心资源,懒加载其他资源),所有的后续和服务器的交互都是通过Ajax调用。Html代码是使用从服务端接收到的数据在客户端生成的。整个页面不会刷新,视图只是在必要时换入换出。有许多的Javascript SPA框架,比如AngularJs,DurandalJs,BackboneJs和EmberJs。ABP可以使用它们中的任何一个,但是提供了使用 AngularJs和DurandalJs的样例。

在多页面(经典)应用中(MPA),客户端向服务端发送请求,服务端代码(ASP.NET MVC 控制器)从数据库中获取数据,然后Razor视图引擎生成html 代码。这些编译后的页面发回给客户端显示。每个新的页面都会导致完整页面的刷新。

SPA和MPA涉及了完全不同的架构。对于后台管理系统来说,SPA是最好的候选者,另一方面,博客更适合MPA模型,因为博客渴望被搜索引擎抓取数据。虽然有很多工具可以使SPA对于搜索引擎可见,但是目前的一般做法就是使用MPA。

最后

ABP平衡了一些最好的框架或者类库,除此之外,ABP自己的类和系统也提供了一个很好的用于N层架构Web应用构建的基础设施,也提供了很轻松地创建分层的解决方案的模板,用作应用的起点。

根据分层我们把项目的类库用解决方案的文件夹整理下:

Guess you like

Origin www.cnblogs.com/aspirant/p/11794053.html