实现域服务作为资源库扩展方法 [英] Implement Domain Services as Extension Methods for the repository

查看:120
本文介绍了实现域服务作为资源库扩展方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的域服务的理解是,他们执行的是相关的库(CRUD相关的任务)的边界之外的任务。



由于.NET允许的扩展方法,为什么没有实现域服务的扩展方法库,从而减少需要实例化既是一个资源库,并在需要时服务?



我会很感激任何意见。


解决方案

我的域服务的理解是,他们执行的是相关的边界之外的任务。库(CRUD相关的任务)




您的理解是我的不同,那就是:




域服务用于封装的的落在一个聚合/实体/值对象的边界之外的逻辑。




库关心的存储的,不是域逻辑,因此,两者是完全不同的事情。



说实话,我越看到的问题在这里周围的站点服务,我越觉得有周围什么的站点服务其实是一般的混乱。我想,这可能是由于之间的不确定性:




  1. 应用服务 - 的(什么UI电话和放大器;如果交易开始)

  2. 基础设施服务 - 的(东西像一个IEmailSenderService,ICreditCardPaymentGateway)

  3. 域名服务 - 的(提供纯净的领域逻辑,就像一个聚合/实体)



吉米·博加德写了的有关其独特的作用好文章



因此,要回答你的问题:这是一个坏主意,因为你会混淆两个截然不同的概念,将违反的 SRP


My understanding of Domain Services is that they perform tasks that are outside the boundaries of the related repository (CRUD related tasks).

Since .Net allows for Extension Methods, why not implement Domain Services as Extension Methods for Repositories and thus reduce the need to instantiate both a repository and a service when required?

I'd appreciate any comments.

解决方案

"My understanding of Domain Services is that they perform tasks that are outside the boundaries of the related repository (CRUD related tasks)."

Your understanding is different to mine, which is:

Domain Services are used to encapsulate domain logic that falls outside the boundary of a single aggregate/entity/value object.

Repositories are concerned with storage, not domain logic, and therefore the two are VERY different things.

To be honest, the more I see questions on here surrounding domain services, the more I feel there is general confusion surrounding what domain services actually are. I think this may due to the ambiguity between:

  1. Application Services - (what the UI calls & where transactions begin)
  2. Infrastructure Services - (things like an IEmailSenderService, ICreditCardPaymentGateway)
  3. Domain Services - (provides pure domain logic, just like an aggregate/entity)

Jimmy Bogard has written a good article about their distinctive roles.

So to answer your question: It's a bad idea because you'd be mixing up two very distinct concepts and would be violating the SRP

这篇关于实现域服务作为资源库扩展方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆