领域驱动设计:领域服务、应用服务 [英] Domain Driven Design: Domain Service, Application Service

查看:36
本文介绍了领域驱动设计:领域服务、应用服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以通过提供一些示例来解释域和应用程序服务之间的区别吗?而且,如果一个服务是一个域服务,我是否会将这个服务的实际实现放在域程序集中,如果是这样,我是否还会将存储库注入该域服务?一些信息会很有帮助.

Can someone explain the difference between domain and application services by providing some examples? And, if a service is a domain service, would I put the actual implementation of this service within the domain assembly and if so, would I also inject repositories into that domain service? Some info would be really helpful.

推荐答案

服务有 3 种风格:领域服务应用服务基础设施服务.

Services come in 3 flavours: Domain Services, Application Services, and Infrastructure Services.

  • 域服务:封装业务逻辑,不自然适合域对象,并且不是典型的 CRUD 操作——这些操作属于存储库.
  • 应用服务:由与您交谈的外部消费者系统(想想Web 服务).如果消费者需要访问 CRUD 操作,它们将在此处公开.
  • 基础设施服务:用于抽象的技术问题(例如MSMQ、电子邮件提供商等).
  • Domain Services : Encapsulates business logic that doesn't naturally fit within a domain object, and are NOT typical CRUD operations – those would belong to a Repository.
  • Application Services : Used by external consumers to talk to your system (think Web Services). If consumers need access to CRUD operations, they would be exposed here.
  • Infrastructure Services : Used to abstract technical concerns (e.g. MSMQ, email provider, etc).

将域服务与域对象一起保留是明智的——它们都专注于域逻辑.是的,您可以将存储库注入您的服务.

Keeping Domain Services along with your Domain Objects is sensible – they are all focused on domain logic. And yes, you can inject Repositories into your Services.

应用服务通常会同时使用域服务存储库来处理外部请求.

Application Services will typically use both Domain Services and Repositories to deal with external requests.

希望有帮助!

这篇关于领域驱动设计:领域服务、应用服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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