3.4 Common Principles 通用原则

Before going into details, let's see some overall DDD principles;

在讨论细节之前,让我们看看DDD的一些总体原则。

3.4.1 Database Provider / ORM Independence 数据驱动程序/ORM的独立性

The domain and the application layers should be ORM / Database Provider agnostic. They should only depend on the Repository interfaces and the Repository interfaces don't use any ORM specific objects.

领域层和应用层应该是与ORM/数据库提供者无关的。它们应该只依赖于存储库的接口,存储库的接口不使用任何ORM的具体对象。

Here, the main reasons of this principle;

这一原则的主要原因如下:

  1. To make your domain/application infrastructure independent since the infrastructure may change in the future or you may need to support a second database type later.

    为了使你的领域层/应用层的基础框架结构独立开来,因为基础框架结构在未来可能会改变,或者你以后可能需要支持第二个数据库类型。
  2. To make your domain/application focus on the business code by hiding the infrastructure details behind the repositories.

    为了使你的领域层/应用层专注于业务逻辑代码,通过隐藏存储库之后的基础框架结构的细节的方式。
  3. To make your automated tests easier since you can mock the repositories in this case.

    为了使你的自动化测试更容易,因为在这种情况下你可以模拟存储库。

As a respect to this principle, none of the projects in the solution has reference to the EntityFrameworkCore project, except the startup application.

作为对这一原则的尊重,除了启动应用程序外,解决方案中的所有项目都没有引用EntityFrameworkCore项目。

3.4.2 Discussion About the Database Independence Principle 关于数据库独立原则的讨论

Especially, the reason 1 deeply effects your domain object design (especially, the entity relations) and application code.Assume that you are using Entity Framework Core with a relational database. If you are willing to make your application switchable to MongoDB later, you can't use some very useful EF Core features.

特别是原因1深深地影响了你的领域对象设计(特别是,实体关系)和应用程序代码。假设你正在使用关系型数据库的Entity Framework Core。如果你以后想让你的应用程序可以切换到MongoDB,你就不能使用一些非常有用的EF Core的功能特性

Examples;例如:

  • You can't assume Change Tracking since MongoDB provider can't do it. So, you always need to explicitly update the changed entities.

    你无法设定变化追踪,因为MongoDB驱动程序不能做到这一点。所以,你总是需要显式地更新变化的实体。
  • You can't use Navigation Properties (or Collections) to other Aggregates in your entities since this is not possible for a Document Database. See the "Rule: Reference Other Aggregates Only By Id" section for more info.

    你不能对实体中的其他聚合体使用导航属性(或集合),因为这在文件型数据库中是不可能的。更多信息请参见 "规则:仅通过标识ID引用其他聚合体 "部分。

If you think such features are important for you and you will never stray from the EF Core, we believe that it is worth stretching this principle. We still suggest to use the repository pattern to hide the infrastructure details. But you can assume that you are using EF Core while designing your entity relations and writing your application code. You can even reference to the EF Core NuGet Package from your application layer to be able to directly use the asynchronous LINQ extension methods, like ToListAsync() (see the IQueryable & Async Operations section in the Repositories document for more info).

如果你认为这样的功能对你很重要,而且你永远不会远离EF Core,我们认为沿用这个原则是值得的。我们仍然建议使用存储库模式来隐藏基础设施的细节。但你可以假设你在设计实体关系和编写应用程序代码时使用的是EF Core。你甚至可以从你的应用层引用EF Core NuGet包,以便能够直接使用异步LINQ的扩展方法,比如ToListAsync()(详见Repositories文档中的IQueryable & Async Operations部分)。

3.4.3 Presentation Technology Agnostic 表现层技术无关性

The presentation technology (UI Framework) is one of the most changed parts of a real world application. It is very important to design the Domain and Application Layers to be completely unaware of the presentation technology/framework. This principle is relatively easy to implement and ABP's startup template makes it even easier.

表现层技术(UI框架)是现实世界应用中变化最大部分的其中之一。将领域层和应用层设计成完全不知道表现层技术/框架是非常重要的。这一原则相对容易实现,ABP的启动模板使其更加容易。

In some cases, you may need to have duplicate logic in the application and presentation layers. For example, you may need to duplicate the validation and authorization checks in both layers. The checks in the UI layer is mostly for user experience while checks in the application and domain layers are for security and data integrity. That's perfectly normal and necessary.

在某些情况下,你可能需要在应用层和表现层编写重复的逻辑。例如,你可能需要在这两层中重复进行验证授权方面的检查。UI层的检查主要是为了用户体验,而应用和领域层的检查是为了安全和数据完整性。这是很正常的,也是必要的。

3.4.4 Focus on the State Changes, Not Reporting 专注于状态的变化,而不是报告

DDD focuses on how the domain objects changes and interactions; How to create an entity and change its properties by preserving the data integrity/validity and implementing the business rules.

DDD的重点是领域对象如何变化和交互;如何通过保持数据的完整性/有效性和实现业务规则的方式来创建一个实体和改变其属性。

DDD ignores reporting and mass querying. That doesn't mean they are not important. If your application doesn't have fancy dashboards and reports, who would use it? However, reporting is another topic. You typically want to use the full power of the SQL Server or even use a separate data source (like ElasticSearch) for reporting purpose. You will write optimized queries, create indexes and even stored procedures(!). You are free to do all these things as long as you don't infect them into your business logic.

DDD忽略了报表和大规模查询。这并不意味着它们不重要。如果你的应用程序没有花哨的仪表盘和报告,谁会使用它?然而,报表是另一个话题。你通常希望使用SQL Server的全部功能,甚至使用一个单独的数据源(如ElasticSearch)来实现报表用途。你会编写优化的查询,创建索引,甚至存储过程(!)。你可以自由地做所有这些事情,只要你不把它们带到你的业务逻辑中。

3.4 Common Principles 通用原则的更多相关文章

  1. linux shell语言编程规范安全篇之通用原则【转】

    shell语言编程规范安全篇是针对bash语言编程中的数据校验.加密与解密.脚本执行.目录&文件操作等方面,描述可能导致安全漏洞或风险的常见编码错误.该规范基于业界最佳实践,并总结了公司内部的 ...

  2. Design Principles (设计原则)

    这是我在2018年4月写的英语演讲稿,可惜没人听得懂(实际上就没几个人在听). 文章的内容是我从此前做过的项目中总结出来的经验,从我们的寝室铃声入手,介绍了可扩展性.兼容性与可复用性等概念,最后提出良 ...

  3. Oracle性能优化之查询语句通用原则

    作者早期文章 Oracle优化 索引是表的一个概念部分 , 用来提高检索数据的效率, ORACLE 使用了一个复杂的自平衡 B-tree 结构 . 通常 , 通过索引查询数据比全表扫描要快 . 当 O ...

  4. (翻译)领域驱动设计实现-Implementing Domain Driven Design

    简介 Implementing Domain Driven Design 领域驱动设计实现 A practical guide for implementing the Domain Driven D ...

  5. erl0001-Erlang 设计原则 process port io

    Erlang原理 (转载自ITEYE cryolite博客 ps:精彩)by Robert Virding This is a description of some of the basic pro ...

  6. Atitit GRASP(General Responsibility Assignment Software Patterns),中文名称为“通用职责分配软件模式”

    Atitit GRASP(General Responsibility Assignment Software Patterns),中文名称为"通用职责分配软件模式" 1. GRA ...

  7. GRASP软件设计的模式和原则

    GRASP 模式:每一个模式描述了一个在我们周围不断重复发生的问题,以及该问题的解决方案的核心.”这是关于模式最经典的定义,作者是建筑大师Christopher Alexander.如果是第一次看到这 ...

  8. 【转】 GRASP(通用职责分配软件模式)模式

    转自:http://www.cnblogs.com/sevenyuan/archive/2010/03/05/1678730.html 及:http://blog.csdn.net/lovelion ...

  9. Design Principle vs Design Pattern 设计原则 vs 设计模式

    Design Principle vs Design Pattern设计原则 vs 设计模式 来源:https://www.tutorialsteacher.com/articles/differen ...

随机推荐

  1. 文件权限的管理以及acl权限列表

    ls -l? 文件名称 上面的命令以长格式显示文件与目录,每一行都是一个文件或目录的属性数据,每个文件或子目录的属性数据又以7个字段显示,各个字段的说明如下: (1)文件类型与权限:该字段共有10个字 ...

  2. 窗口函数至排序——SQLServer2012可高用

    常用到的窗口函数 工作中要常对数据进行分析,分析前要对原始数据中找到想要的格式,数据原本存储的格式不一定时我们想要的,要在基础上进行一定的处理,下面介绍的几种方式是常用的数据排序的集中方式,包含 排名 ...

  3. NumPy的基本操作

    1 简介 NumPy 是用于处理数组的 python 库,部分用 Python 编写,但是大多数需要快速计算的部分都是用 C 或 C ++ 编写的.它还拥有在线性代数.傅立叶变换和矩阵领域中工作的函数 ...

  4. adb 常用命令大全(4)- 应用管理

    查看应用列表 语法格式 adb shell pm list packages [-f] [-d] [-e] [-s] [-3] [-i] [-u] [--user USER_ID] [FILTER] ...

  5. Golang入门学习(二):控制分支

    文章目录 @[TOC] 1. 控制分支 1.1 if-else分支 1.2 switch分支 1.4 while 和do...while循环结构 1.5 多种循环结构 1.6 break 1.7 co ...

  6. [推荐]MyBatis 核心技术与面试 34 讲

    MyBatis 核心技术与面试 34 讲 职业生涯中常被问到: 如何成为某方面的高手? 如何快速搞定某项技术? 我现在的水平处于什么阶段? -- 我暗暗想,我们从小学到中学到大学,经历了大考三六九.小 ...

  7. 论文解读(PCL)《Prototypical Contrastive Learning of Unsupervised Representations》

    论文标题:Prototypical Contrastive Learning of Unsupervised Representations 论文方向:图像领域,提出原型对比学习,效果远超MoCo和S ...

  8. VSCode Remote-SSH 连接服务器

  9. 整理STC延时函数时遇到的玄学问题

    void Delay { unsigned char i, j; i = 11; j = 190; do { while (--j); } while (--i); } void Delay { un ...

  10. TP5 pc和wap跳转404

    在config.php中配置 // HttpException异常 'http_exception_template' => [ // 定义404错误的重定向页面地址 404 => isW ...