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. springboot通过AOP和自定义注解实现权限校验

    自定义注解 PermissionCheck: package com.mgdd.sys.annotation; import java.lang.annotation.*; /** * @author ...

  2. Linux基础命令(基于CentOS7)

    1.帮助相关命令 man 查看普通命令的帮助 --help 只能查看内置命令 info 查看一个命令的更多信息 type 查看是否为内置命令 2.关机重启 shutdown -h 关机 -r 重启 - ...

  3. Appium自动化(8) - 可定位的控件属性

    如果你还想从头学起Appium,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1693896.html 前言 在前面几篇文章可以看到,一个 ...

  4. openswan一条隧道多保护子网配置

    Author       : Email         : vip_13031075266@163.com Date          : 2021.01.22 Copyright : 未经同意不得 ...

  5. Sentry Web 性能监控 - Trends

    系列 1 分钟快速使用 Docker 上手最新版 Sentry-CLI - 创建版本 快速使用 Docker 上手 Sentry-CLI - 30 秒上手 Source Maps Sentry For ...

  6. 硕盟 type-c转接头转接口(HDMI+VGA+USB3.0+PD3.0)四合一拓展坞

    硕盟SM-T54是一款 TYPE C转HDMI+VGA+USB3.0+PD3.0四合一多功能扩展坞,支持四口同时使用,您可以将含有USB 3.1协议的电脑主机,通过此产品连接到具有HDMI或VGA的显 ...

  7. linux主机安全加固-个人经验

    说明:我并没有一个系统的网络安全知识体系,随笔里面提到的内容是个人在从事运维行业这几年中总结出来的一点经验,仅供大家参考. 说到linux主机安全加固,我可以想到的就是三个方向吧,基线整改.访问控制和 ...

  8. XSS注入

    XSS 原理: 程序对输入和输出没有做合适的处理,导致"精心构造"的字符输出在前端时被浏览器当作有效代码解析执行从而产生危害. 分类 : 危害:存储型 > 反射型 > ...

  9. Docker系列(16)- 容器数据卷

    什么是容器数据卷 docker的理念回顾 将应用和环境打包成一个镜像 数据?如果数据都在容器中,那么我们容器删除,数据就会丢失!新增一个需求:数据可以持久化 MySQL,容器删了等于删库跑路!新增一个 ...

  10. win10系统安装jdk

    应用程序形式 文件包形式 环境变量配置 https://www.cnblogs.com/gz9218/p/2ae083861f6749899b1b800faabe1c17.html