Introduction
Layering of an application's codebase is a widely accepted technique to help reduce complexity and improve code reusability. To achieve layered architecture, ASP.NET Boilerplate follows the principles of Domain Driven Design.
分层应用程序的代码是一个被广泛接受的技术有助于降低复杂性和提高代码的可重用性。实现分层架构,ASP.NET样板如下领域驱动设计的原则。
Domain Driven Design Layers
There are four fundamental layers in Domain Driven Design (DDD):
- Presentation Layer: Provides an interface to the user. Uses the Application Layer to achieve user interactions.
- Application Layer: Mediates between the Presentation and Domain Layers. Orchestrates business objects to perform specific application tasks.
- Domain Layer: Includes business objects and their rules. This is heart of the application.
- Infrastructure Layer: Provides generic technical capabilities that support higher layers mostly using 3rd-party libraries.
-
表示层:为用户提供一个接口。使用应用程序层实现用户交互。
应用层:在表示层和域层之间进行中介。编排业务对象来执行特定的应用任务。
域层:包含业务对象及其规则。这是应用程序的核心。
基础架构层:提供一般技术支持高级层的功能,主要使用第三方库。
ASP.NET Boilerplate Application Architecture Model
In addition to DDD, there are also other logical and physical layers in a modern architected application. The model below is suggested and implemented for ASP.NET Boilerplate applications. ASP.NET Boilerplate not only makes to implement this model easier by providing base classes and services, but also provides startup templates to directly start with this model.
在国内也有在现代架构的应用逻辑层和物理层。建议和实施ASP.NET样板应用下面的模型。ASP.NET样板不仅使该模型的实现提供方便的基础类和服务,而且还提供了启动模板直接从这个模型。
Client Applications
These are remote clients uses the application as a service via HTTP APIs (API Controllers, OData Controllers, maybe GraphQL endpoint). A remote client can be a SPA, a mobile application or a 3rd-party consumer.Localization and Navigation can be done inside this applications.
这些都是远程客户使用应用程序通过HTTP API服务(API控制器、数据控制器,也许graphql端点)。远程客户机可以是spa、移动应用程序或第三方用户,本地化和导航可以在这个应用程序中完成。
Presentation Layer
ASP.NET [Core] MVC (Model-View-Controller) can be considered as the presentation layer. It can be a physical layer (uses application via HTTP APIs) or a logical layer (directly injects and uses application services). In either case it can include Localization, Navigation, Object Mapping, Caching, Configuration Management, Audit Logging and so on. It should also deal with Authorization, Session, Features (for multi-tenant applications) and Exception Handling.
Distributed Service Layer(分布式服务层)
This layer is used to serve application/domain functionality via remote APIs like REST, OData, GraphQL... They don't contain business logic but only translates HTTP requests to domain interactions or can use application services to delegate the operation. This layer generally include Authorization, Caching, Audit Logging, Object Mapping, Exception Handling, Session and so on...
这一层是用来为应用程序域通过远程API like rest,odata,GraphQL…它们不包含业务逻辑,但只将HTTP请求转换为域交互,或者可以使用应用程序服务来委托操作。此层通常包括授权、缓存、审计日志记录、对象映射、异常处理、会话等…
Application Layer
Application layer mainly includes Application Services those use domain layer and domain objects (Domain Services, Entities...) to perform requested application functionalities. It uses Data Transfer Objects to get data from and to return data to presentation or distributed service layer. It can also deal with Authorization, Caching, Audit Logging, Object Mapping, Session and so on...
应用层主要包括使用域层和域对象(域服务、实体…)来执行请求的应用功能的应用服务。它使用数据传输对象从数据中获取数据,并将数据返回到表示或分布式服务层。它还可以处理授权、缓存、审计日志记录、对象映射、会话等等…
Domain Layer
This is the main layer that implements our domain logic. It includes Entities, Value Objects, Domain Services to perform business/domain logic. It can also include Specifications and trigger Domain Events. It defines Repository Interfaces to read and persist entities from data source (generally a DBMS).
这是实现我们域逻辑的主要层。它包括实体、值对象、域服务来执行业务/域逻辑。它还可以包含规范和触发域事件。它定义了从数据源(通常是DBMS)读取和保存实体的存储库接口。
Infrastructure Layer
Infrastructure layer makes other layers working: It implements repository interfaces (using Entity Framework Core for example) to actually work with a real database, it may include integration to a vendor to send emails and so on. This is not a strict layer below all layers, but actually supports other layers by implementing abstract concepts of them.
基础结构层使其他层发挥作用:它实现了存储库接口(例如使用实体框架核心)来实际工作数据库,它可以包括向供应商发送电子邮件等集成。这不是所有层之下的严格层,但是通过实现它们的抽象概念实际上支持其他层。