3.4 Common Principles 通用原则
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;
这一原则的主要原因如下:
- 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.
为了使你的领域层/应用层的基础框架结构独立开来,因为基础框架结构在未来可能会改变,或者你以后可能需要支持第二个数据库类型。 - To make your domain/application focus on the business code by hiding the infrastructure details behind the repositories.
为了使你的领域层/应用层专注于业务逻辑代码,通过隐藏存储库之后的基础框架结构的细节的方式。 - 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 通用原则的更多相关文章
- linux shell语言编程规范安全篇之通用原则【转】
shell语言编程规范安全篇是针对bash语言编程中的数据校验.加密与解密.脚本执行.目录&文件操作等方面,描述可能导致安全漏洞或风险的常见编码错误.该规范基于业界最佳实践,并总结了公司内部的 ...
- Design Principles (设计原则)
这是我在2018年4月写的英语演讲稿,可惜没人听得懂(实际上就没几个人在听). 文章的内容是我从此前做过的项目中总结出来的经验,从我们的寝室铃声入手,介绍了可扩展性.兼容性与可复用性等概念,最后提出良 ...
- Oracle性能优化之查询语句通用原则
作者早期文章 Oracle优化 索引是表的一个概念部分 , 用来提高检索数据的效率, ORACLE 使用了一个复杂的自平衡 B-tree 结构 . 通常 , 通过索引查询数据比全表扫描要快 . 当 O ...
- (翻译)领域驱动设计实现-Implementing Domain Driven Design
简介 Implementing Domain Driven Design 领域驱动设计实现 A practical guide for implementing the Domain Driven D ...
- erl0001-Erlang 设计原则 process port io
Erlang原理 (转载自ITEYE cryolite博客 ps:精彩)by Robert Virding This is a description of some of the basic pro ...
- Atitit GRASP(General Responsibility Assignment Software Patterns),中文名称为“通用职责分配软件模式”
Atitit GRASP(General Responsibility Assignment Software Patterns),中文名称为"通用职责分配软件模式" 1. GRA ...
- GRASP软件设计的模式和原则
GRASP 模式:每一个模式描述了一个在我们周围不断重复发生的问题,以及该问题的解决方案的核心.”这是关于模式最经典的定义,作者是建筑大师Christopher Alexander.如果是第一次看到这 ...
- 【转】 GRASP(通用职责分配软件模式)模式
转自:http://www.cnblogs.com/sevenyuan/archive/2010/03/05/1678730.html 及:http://blog.csdn.net/lovelion ...
- Design Principle vs Design Pattern 设计原则 vs 设计模式
Design Principle vs Design Pattern设计原则 vs 设计模式 来源:https://www.tutorialsteacher.com/articles/differen ...
随机推荐
- ubantu硬盘不足,无法启动
我的ubantu虚拟机经过我一顿操作后,就起不来了.然后经过多方询问,广集天下良方,最终发现是由于分配的硬件空间不足导致的.现象如下: 通过查看 root@ubantu:/snap# df -h Fi ...
- SQL-INSERT触发器练习
&练习一 有这样的一个基础表A,字段包括:id.type.value.create_time,主要是记录某个类型的状态变化时间和值.在插入类型(type)为'runtime' 的数据时,根据前 ...
- Vue 路由跳转报错 Error: Avoided redundant navigation to current location: "/XXX".
在router文件夹下的index.js中加入红色字体代码即可解决 import Vue from 'vue' import VueRouter from 'vue-router' Vue.use(V ...
- C#取汉字首字母,汉字全拼
使用类库为 https://gitee.com/kuiyu/dotnetcodes/tree/master/DotNet.Utilities/%E6%B1%89%E5%AD%97%E8%BD%AC%E ...
- Fastjson 1.2.22-24 反序列化漏洞分析(2)
Fastjson 1.2.22-24 反序列化漏洞分析(2) 1.环境搭建 我们以ubuntu作为被攻击的服务器,本机电脑作为攻击者 本机地址:192.168.202.1 ubuntu地址:192.1 ...
- 什么是maven与maven的使用过程(例如在idea创建maven工程(重点讲讲idea创建使用maven管理的web工程,并且部署到tomcat上))
什么是maven与maven的使用过程(例如在idea创建maven工程) (重点讲讲idea创建使用maven管理的web工程项目,并且部署到tomcat服务器上) 一.什么是maven? 1, M ...
- 详解Java中==和equals()的区别
众所周知,在 Java 编程中,程序员通常会使用==或equals()来简单的比较地址,内容是否相等.而这两者之间的使用区别,对于初学 Java 的同学来说可能会比较迷糊.我将根据下面的几段示例程序, ...
- composer 包 slim使用案例,一个简单的路由解决方案
nginx配置文件修改 location / { try_files $uri /index.php$is_args$args; } 设置好nginx伪静态,把所有的请求方式都转向到index.php ...
- Jmeter扩展组件开发(1) - 创建maven工程
前言 没有安装IDEA的伙伴先安装.url:https://www.cnblogs.com/gltou/p/14956060.html 扩展开发实现的两种方式 继承AbstracJavaSampler ...
- Docker系列(21)- DockerFile介绍
DockerFile介绍 dockerfile是用来构建docker镜像的文件!命令参数脚本! 构建步骤 编写一个dockerfile文件 docker build构建成为一个镜像 docker ru ...