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 ...
随机推荐
- CountDownLatch能不能在多个线程上添加await?
在CountDownLatch类的使用过程中,发现了一个很奇怪的现象: CountDownLatch countDownLatch = new CountDownLatch(2); Runnable ...
- 【算法】使用Golang实现加权负载均衡算法
背景描述 如下图所示,负载均衡做为反向代理,将请求方的请求转发至后端的服务节点,实现服务的请求. 在nginx中可以通过upstream配置server时,设置weight表示对应server的权重. ...
- tslib移植arm及使用
测试平台 宿主机平台:Ubuntu 12.04.4 LTS 目标机:Easy-ARM IMX283 目标机内核:Linux 2.6.35.3 tslib 1.4 下载 https://gitlab. ...
- 定时器及PWM
1 定时器 1.1 定时器分类 对于STM32来说,定时器可分为基本定时器.通用定时器.高级定时器三类,后者包括前者的全部功能.以stm32f1系列为例,TIM6和TIM7为基本定时器,TIM2~TI ...
- expression动态构成
http://blog.csdn.net/tastelife/article/details/7340205 http://blog.csdn.net/tastelife/article/detail ...
- windows 创建cmd alias
windows cmd bat alias 命令 别名 1. 创建文件 C:\cmd-alias.bat @doskey sayhello=echo Hello $* @doskey cattxt=t ...
- file_get_contents('php://input') 数据如何转换成数组
前台表单页:demo01.html 后台:demo01.php 输出结果: 备注:若前台通过Ajax的post提交过来的是json数据,需要对json数据进行解析:$data = json_decod ...
- "错误: 找不到或无法加载主类"解决办法
前言:记上次一个找了个把小时的问题(很烦这些配置) 原因: 从svn下checkOut的项目 在application的配置的输出class路径为main,而class文件路径是在项目名的根路径下,所 ...
- kettle 多表全删全插同步数据 两种方案
背景: 接到上级指示,要从外网某库把数据全部导入到内网,数据每天更新一次即可,大约几百万条数据,两个库结构一样,mysql的,两台数据库所在服务器都是windows server的,写个java接口实 ...
- 前端规范之CSS规范(Stylelint)
代码规范是软件开发领域经久不衰的话题,几乎所有工程师在开发过程中都会遇到或思考过这一问题.而随着前端应用的大型化和复杂化,越来越多的前端团队也开始重视代码规范.同样,前段时间,笔者所在的团队也开展了一 ...