DDD基础设施服务 [英] DDD Infrastructure services

查看:100
本文介绍了DDD基础设施服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习DDD,在基础结构层中我有些迷路了.

I am learning DDD and I am a little bit lost in Infrastructure layer.

据我了解,所有良好的DDD应用程序"应具有4个层:表示层,应用程序,域和基础结构.应该使用存储库访问数据库.存储库接口应在域层和存储库实现中-在基础结构中(请参考 DDD :在哪里保留域接口,基础结构?).

As I understand, "all good DDD applications" should have 4 layers: Presentation, Application, Domain and Infrastructure. Database should be accessed using Repositories. Repository interfaces should be in Domain layer and repository implementation - in Infrastructure (reference DDD: Where to keep domain Interfaces, the Infrastructure?).

应用程序,域和基础结构层应该/可以具有服务(参考

Application, Domain and Infrastructure layer should/may have services (reference Services in Domain-Driven Design), for example EmailService in Infrastructure layer which sends e-mail messages.

但是,在基础结构层内部,我们有存储库实现,用于访问数据库.那么,在这种情况下,存储库是数据库服务吗?基础结构服务和存储库有什么区别?

BUT, inside Infrastructure layer we have repository implementations, which are used to access database. So, in this case, repositories are database services? What is the difference between Infrastructure service and repository?

提前谢谢!

推荐答案

使用DDD定义,存储库与服务不同.存储库与实体(通常是聚合根)直接相关.服务定义的行为实际上并不属于您域中的单个实体.您可以在每一层中找到服务,尽管它们要解决的问题类型因层而异,并且可能与DDD的概念性服务不同.

Sticking with DDD definitions, a Repository is different than a Service. A Repository directly correlates to an Entity, often an Aggregate Root. A Service defines behaviors that don't really belong to a single Entity in your domain. You can absolutely find Services in every layer, though the types of problems they address differ from layer to layer and may be different from DDD's conceptual Service.

在概念级别上工作时,DDD存储库与DDD服务的不同之处在于,它专门与实体持久性相关联.服务可以解决您可能遇到的任何域,应用程序或基础结构问题.

When working at the conceptual level, a DDD Repository differs from a DDD service in that it is specifically tied to Entity persistence. A Service can address any Domain, Application, or Infrastructure problem you may have.

您到处都遇到DDD的术语冲突.例如,DDD存储库与Martin Fowler的PoEAA书中的存储库模式不同,尽管它可能会采用这种模式.这通常会使许多人感到困惑.

You run into terminology clashes with DDD all over the place. For instance, a DDD Repository is NOT the same thing as the Repository pattern found in Martin Fowler's PoEAA book, though it may employ such a pattern. This is often a source of confusion for many people.

如果您始终将域模型放在所有所做工作的中心,它将对DDD有所帮助.在分层DDD应用程序方面,我经常选择 Jeffrey Palermo的洋葱架构.一探究竟.下载 CodeCampServer ,这是使用此体系结构的示例应用程序.我认为这非常适合DDD编程.

It helps with DDD if you always keep the Domain Model at the very center of everything you do. When it comes to layering DDD apps, I often choose Jeffrey Palermo's Onion Architecture. Check it out. Download CodeCampServer, an example app using this architecture. I think it's a perfect fit for DDD programming.

祝你好运!

这篇关于DDD基础设施服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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