DDD~领域层
再论Domain与Infrastructure
在面向领域的设计中,领域层(Domain)实现上是位于最底层的,其它层有对它的引用,包括基础设施层(Infrastructure)也是去引用领域层的,我认为,这是对的,事实上,在Domain中会规定如何去进行数据持久化的操作,包括方法名,方法签名等等,而采用哪种架构去实现这种持久化的方法则是Infrastructure层需要做的,这种设计绝对是把领域,业务放在第一位的,完全符合Eric 的DDD。
Domain.Core Layer & Domain Layer
我们在进行软件设计时,一个习惯就是把仅供代码抽象出来,这是对的,也是符合标准的,对于domain层我们会把与具体领域无关的代码抽象成一个domain.core,这个项目位于整个DDD解决方案的最底层,而具体的domain则会引入它,看一下我们的DDD中的domain层
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPgAAADNCAIAAAAaBCpCAAANvElEQVR4nO2dzWscyRmH9+/QoQ8GGywddfA1dI7B5LAX62wv7M3/gjHLwGphQw7LxsEHBVuYPWQH39Y+DIsnm6NJWFnfkjU9H5Zkw0heKGISUA7dND313VU109VVv4dC1NRUvVUjPVMqq/v1fDadfpy8+zB592E6/TidfiQA+M3p6Yey/OvfO9xS7ZOL/RlEB+3CQvTJh8mkeLz66AoFxecC0VGiKBAdJYoSpuh1D3CNLxhl3iVY0W+tr2oWiB5DMRd9PPkw9lv0i+mlskD0SEqbRP/8B347ew6xFL2K/bINgrhdAMpqi0S/+/zqt0+cdkLI5uvsxtNsaSO78TTbfJ3lupeid3/spmmapmn3x+7F9DJN0/KrZEcvDVu8atUZIbqr0g7R7z6/+s9/+T91QsjSRvbg1fDFr4MHr4ZLGzOi55aPR5OL6eX+3kE6i/+io7gqNqK/H0/eL0D0u8+vPv1P+Htc9IeUXPQ0TX/5xy/Vs4rNjl5dg+h0QbVwH8rPJKKn2NmV06GUxXfRq5ZLdvRqkYhus6NTFfYrt7LKiKv8XcFt505RN3LMxWvRKcvlol9ML1nRHz36a/XoYrOj64i++oiz1PmJzvZR/rqItliIPn4/Hs9R9M9/uPrt0xUF200ueul6mqYvX7zU//OiJzu6chmig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9Sj/Xi/A+XNjXB6IXJEFkGFFxdG7GqhtT0uIzEL0gCSLDiIopuQHLOGa1pUWuQ/SC8mfW3gwjIr5/UD8O97TDbSGz7yg2LBtN8yglWrbN+8pc9J29bGcvC0z0ADKM2Ip9ZKouisztIwoowmyUEohekASRYSSqUFPUjcOGkoxiu8lbuCtUxqkLRC9Igs4wsozDdtN/U3Fx/pQSiF7Q9gwjdhRFtY8kDlunulHtollEL0H5otjXJYpfCwvRd7Od3XBER4aRc+TvrgUD0cEcsd+JXQHRQRRAdBAFEB1EAUQHUQDRQRRAdC06nU46S9MrAvUwF317N9v2UnTn+ROdTufhw68uppdlgeitI0DRbXKFUh6l5flDiN5GAhQ9scgVyj1WFpHoTi5Wl6Ek8SV9XM0VGGGKrpMrxMVG9Hlf8YbWNoQpOtHIFeLCPbpwEc07PyC6DRai72TbO/6KToxyhWxEJ6r8GlE3Irhfj9tB0oeNI1mSZDFUo8PzWIMEK7pOFgWLpejVBVD1WhXC23eVLa4ia8ZpFzaiD7Z3Bn6KbmY5cSQ6Ubmi829KG9GpRnYL14wD0X0X3cxy4u6MXsuV+YmOHb0kQNE1c4W4WIouOgGzJsm7STpI+mgOLBuVcdgObM+2EKDoNrlCro4uJS3VIjzMRX+zM3jjpeg2uBWdu1mCRoDoIAogOogCiA6iAKKDKIDoIAosRN8evNmG6KAdeC26Ta4Q9V82S4rDBQNvMRP9/4+aTwcOMVMkAAAAAElFTkSuQmCC" alt="" />
domain.core中有数据持久化的规范,规约实现Specification及一些公用的功能代码。
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOcAAAFxCAIAAAAH3iidAAAYC0lEQVR4nO2dv48cyXXH9+9g0AEBHsCdkMGlRjs0FgoUEVBEnAH/DRcdDsIAWgE6XSDIJ27A4A6MrAmY6BQshBsr2ORgQQMYtiPtyYYoGCB5OlVKBy22e6tevXpdXV0/Xn8/WCx6e+rn9IdvitP1Zs4MAPXxpz/97/jzb7/7d+vnrPTwACDIbe37l4+E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h1H+LJae2sgWVGp7WlchkG5GvNjkocYNr01XJP8pGeaZ8Zcz3otBa5DLrRaW0qSu0K7xzW66tFYC0HchnqBNaC9oC1oD1gLWgPWAvaA9aC9shnbZL8AgBMTmuX5BcAMCWftd2C/IKRH//qR+9fPhp+fv6bnxlj3r98NP729RvxLn2R9/bJG7NzhyEp3/pti6zWLswvGJT93j//w89/87Mf/+pHh6//ZTR4+GG6jhtwRK2FdM5ml+D+BHmbashqrVmWX/D+5aO///Tv/vzqz9ZJw8Za07K1wTHA2hzWmgX5Be9fPvqnL/7ROiOMte5Lre+M641vM5T1gk627JbxvfT7OnL7ZeYVbJYs45sCWVIyZr7WcnJbuyS/YHmsjTiwrqV74FqS8IDv3TqOPsMMgyGuVhJ4a/8P0AgbKxxzyQwAAAAASUVORK5CYII=" alt="" />
具体的domain项目中包括三部分内容,具体业务规范(如产品业务规范Products),数据模型POCO实体,用于网络传输的DTO实体(这部分可以单拿出来,本例直接放在了实体层),我们先来看一下products这个业务规范:
IProductRepository:它是产品实体的数据持久化规范,Infrastructure层会去实现它,这里不会关心Infrastructure是采用linq to sql还是ef,我只规定要做什么,至少怎么去做,由Infrastructure自己去决定!
public interface IProductRepository : IExtensionRepository<Product>
{
/// <summary>
/// 获取产品列表
/// </summary>
/// <returns></returns>
IQueryable<Product> GetProduct(); /// <summary>
/// 建立产品
/// </summary>
void AddProduct(Product entity); /// <summary>
/// 修改产品
/// </summary>
void ModifyProduct(System.Linq.Expressions.Expression<Action<Product>> entity);
}
ProductSpecification:这是一个与业务息息相关的规约类,它会根据具体业务去设计每一个业务的具体规约
/// <summary>
/// 通过用户信息得到他的订单列表
/// </summary>
public class ProductSpecification : Specification<Product>
{
string _productName = default(string);
public ProductSpecification(string productName)
{
_productName = productName;
}
public override Expression<Func<Product, bool>> SatisfiedBy()
{
Specification<Product> spec = new TrueSpecification<Product>();
if (string.IsNullOrWhiteSpace(_productName))
spec &= new DirectSpecification<Product>(o => o.ProductName.Contains(_productName));
return spec.SatisfiedBy();
}
}
网络传输对象DTO,它是在进行WEB通讯时为了减少网站负载,而提出的新的实体层,将与本服务有关的实体属性提出,形成一个新的实体,这在SOA服务
中用的比较多。
[DataContract]
public class ProductDTO
{
[DataMember]
[DisplayName("商品ID")]
public int ProductID { get; set; }
[DataMember]
[DisplayName("商品名称")]
public string ProductName { get; set; }
[DataMember]
[DisplayName("建立日期")]
public System.DateTime CreateDate { get; set; }
[DataMember]
public int SaleCount { get; set; }
[DataMember]
public Nullable<int> ClickCount { get; set; }
[DataMember]
[DisplayName("产品描述")]
public string Info { get; set; }
[DataMember]
public int UserID { get; set; }
[DataMember]
[DisplayName("销售价格")]
public decimal SalePrice { get; set; }
[DataMember]
[DisplayName("折扣")]
public int Discount { get; set; }
}
数据模型EDMX,这种模块我们称为entity frameworks模型,也叫EF模型,它可以把物理数据库映射到EDMX文件中,它是以XML形式保存的,而我们
的POCO简单数据实体也可以由工具自动生成,这些实体与原始数据表一一对应。ef poco 模型实体采用partial class方便开发人员以后对实体类进行扩展。
public partial class Product
{
public Product()
{
this.ProductDetail = new HashSet<ProductDetail>();
} public int ProductID { get; set; }
public string ProductName { get; set; }
public System.DateTime CreateDate { get; set; }
public int SaleCount { get; set; }
public Nullable<int> ClickCount { get; set; }
public string Info { get; set; }
public int UserID { get; set; }
public decimal SalePrice { get; set; }
public int Discount { get; set; }
public System.DateTime UpdateDate { get; set; } public virtual User_Info User_Info { get; set; }
public virtual ICollection<ProductDetail> ProductDetail { get; set; }
}
最后,我们看一个domain与Infrastructure之间的数据通信,它们一般使用IOC容器进行实现,像Autofac和Unity都是不错的选择,而unity是一个强大的工具
集,它不仅包括IOC的功能,而且还提供了对AOP的实现!下次我们将着重介绍一下Unity在DDD中的使用,介请期待!
DDD~领域层的更多相关文章
- C#进阶系列——DDD领域驱动设计初探(七):Web层的搭建
前言:好久没更新博客了,每天被该死的业务缠身,今天正好一个模块完成了,继续来完善我们的代码.之前的六篇完成了领域层.应用层.以及基础结构层的部分代码,这篇打算搭建下UI层的代码. DDD领域驱动设计初 ...
- DDD领域驱动设计之领域基础设施层
1.DDD领域驱动设计实践篇之如何提取模型 2.DDD领域驱动设计之聚合.实体.值对象 其实这里说的基础设施层只是领域层的一些接口和基类而已,没有其他的如日子工具等代码,仅仅是为了说明领域层的一些基础 ...
- DDD领域驱动设计之运用层代码
1.DDD领域驱动设计实践篇之如何提取模型 2.DDD领域驱动设计之聚合.实体.值对象 3.DDD领域驱动设计之领域基础设施层 4.DDD领域驱动设计之领域服务 5.整体DEMO代码 什么是运用层,说 ...
- DDD实战进阶第一波(五):开发一般业务的大健康行业直销系统(实现产品上下文领域层)
从这篇文章开始,我们根据前面的DDD理论与DDD框架的约束,正式进入直销系统案例的开发. 本篇文章主要讲产品上下文中的领域层的主要实现,先简单讲下业务方面的需求:产品SPU与产品SKU,产品SPU主要 ...
- [Abp vNext 源码分析] - 5. DDD 的领域层支持(仓储、实体、值对象)
一.简要介绍 ABP vNext 框架本身就是围绕着 DDD 理念进行设计的,所以在 DDD 里面我们能够见到的实体.仓储.值对象.领域服务,ABP vNext 框架都为我们进行了实现,这些基础设施都 ...
- DDD领域驱动设计初探(七):Web层的搭建
前言:好久没更新博客了,每天被该死的业务缠身,今天正好一个模块完成了,继续来完善我们的代码.之前的六篇完成了领域层.应用层.以及基础结构层的部分代码,这篇打算搭建下UI层的代码. DDD领域驱动设计初 ...
- Java开发架构篇:DDD模型领域层决策规则树服务设计
作者:小傅哥 博客:https://bugstack.cn 沉淀.分享.成长,让自己和他人都能有所收获! 一.前言 在上一章节介绍了领域驱动设计的基本概念以及按照领域驱动设计的思想进行代码分层,但是仅 ...
- ABP领域层
1.实体Entites 1.1 概念 实体是DDD(领域驱动设计)的核心概念之一. 实体是具有唯一标识的ID且存储在数据库总.实体通常被映射成数据库中的一个表. 在ABP中,实体继承自Entity类. ...
- ABP(现代ASP.NET样板开发框架)系列之10、ABP领域层——实体
点这里进入ABP系列文章总目录 基于DDD的现代ASP.NET开发框架--ABP系列之10.ABP领域层——实体 ABP是“ASP.NET Boilerplate Project (ASP.NET样板 ...
随机推荐
- 标题编辑 AndroidTagGroup
地址: https://github.com/2dxgujun/AndroidTagGroup
- vim的跨文件复制粘贴
1.用vim打开一个文件,例如:a.cpp 2.在普通模式下,输入:":sp"(不含引号)横向切分一个窗口,或者":vsp"纵向切分一个窗口,敲入命令后,你将看 ...
- iptables之LOG目标 被拦截包分析
iptables之LOG目标 问题 在iptables的INPUT链中发现有大量未知包被拦截,这种情况就有两种可能,一是自己的某个服务的iptables端口没有打开,二是服务器正在遭受攻击 分析 这就 ...
- web应用程序传递连接字符串给FastReport数据源
public static FastReport.Report fr = new FastReport.Report(); public static FastReport.EnvironmentSe ...
- MIMO下的MES均方误差详细推导过程
- 关于mock server
这篇技术博客是在知乎上看到的 知乎js大神张云龙写的 这里贴过来记录下,如果侵权 请告知将及时删除. --------------------------- 为了更好的分工合作,让前端能在不依赖后端环 ...
- SQL Server 全文索引创建
在安装数据库管理系统SQL Server 后,默认情况下全文索引的服务是没有开启的 ,所以首先需要先开启服务,在sql server配置管理器中 (sql server configuration M ...
- HDU 1010 Tempter of the Bone
题意:从开始位置走到结束位置,恰好走 t 步 YES 否则 NO 搜索题,由于是恰好走到,所以用到了奇偶剪枝 什么是奇偶剪枝,我也是刚知道 所给步数为 t ,起始位置坐标 (begin_x,begin ...
- web前端防治重复提交
web前端开发中防治重复提交 web前端数据请求或者表单提交往往通过对dom的点击事件来操作,但是往往因为认为点击过快(少年手速挺快的嘛),或者因为响应等待使得用户误人为没操作而重复很多次点击,造成表 ...
- 测试架构图 High Level 产品技术(无事来更新,证明这个博客还是Live的)
一个完整的产品测试所需要掌握的产品技术架构. 1.最底层硬件平台(服务器与存储) 对于一个大型商业解决方案来说,性能与可靠性是非常重要的要求,那么服务器与存储就是专门来满足需求的. 服务器: 服务器端 ...