DDD:在哪里保留域接口,基础结构? [英] DDD: Where to keep domain Interfaces, the Infrastructure?

查看:74
本文介绍了DDD:在哪里保留域接口,基础结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在基础结构层内将域层的所有接口(模块,模型,实体,域服务等)全部分组是否有意义?如果没有,创建一个共享的项目/组件将所有这些分组到共享库中是否有意义?毕竟,基础结构层的定义包括域,应用程序和UI层的共享库。

Does it make sense to group all Interfaces of your Domain Layer (Modules, Models, Entities, Domain Services, etc) all within the Infrastructure layer? If not, does it make sense to create a "shared" project/component that groups all of these into a shared library? After all, the definition of "Infrastructure Layer" includes "shared libraries for Domain, Application, and UI layers".

我正在考虑围绕DDD层设计代码库:UI,应用程序,域,基础结构。这将分别创建4个项目。我的意思是,您是从域层引用基础结构层的。但是,如果您在域层项目中定义接口(例如IPost),则在定义IPostRepository.Save(IPost post)方法时必须从基础结构项目中引用域层项目时,您将具有循环引用。 。因此,定义共享库中的所有接口的想法。

I am thinking of designing my codebase around the DDD layers: UI, Application, Domain, Infrastructure. This would create 4 projects respectfully. My point is, you reference the Infrastructure Layer from the Domain Layer. But if you define the interfaces in the Domain Layer project, say for IPost, then you'll have a circulur reference when you have to reference the Domain Layer project from the Infrastructure project when you are defining the IPostRepository.Save(IPost post) method. Hence, the idea of "define all Interfaces in the Shared library".

也许存储库不应该期望对象被保存(IPostRepository.Save(IPost post);但是取而代之的是,期望对象的参数(尽管在Save()中可能是很长的一组参数)。鉴于此,这可能是一个理想的情况,它表明对象何时变得过于复杂,应该查看附加的Value Objects。

Perhaps the repositories should not expect an object to save (IPostRepository.Save(IPost post); but instead, expect the params of the object (that could be a long set of params in the Save() though). Given, this could be an ideal situation that shows when an object is getting overly complex, and additional Value Objects should be looked into for it.

有想法吗?

推荐答案

关于放置位置在存储库中,我个人总是将存储库放在专用的基础结构层(例如MyApp.Data.Oracle)中,但在域层中声明存储库必须符合的接口。

在我的项目中应用层必须访问域和基础结构层,因为它负责配置域和基础结构层。

应用层负责注入适当的基础结构进入域。该域不知道与之通信的基础架构,只知道如何调用它。当然,我使用诸如Structuremap之类的IOC容器将依赖项注入到域中。
同样,我没有声明DDD建议采用这种方式来构建项目,这只是我构建应用程序的方式。
喝彩。

Concerning where to put the repositories, personally I always put the repositories in a dedicated infrastructure layer (e.g . MyApp.Data.Oracle) but declare the interfaces to which the repositories have to conform to in the domain layer.
In my projects the Application Layer has to access the Domain and Infrastructure layer because it’s responsible to configure the domain and infrastructure layer.
The application layer is responsible to inject the proper infrastructure into the domain. The domain doesn’t know to which infrastructure it’s talking to, it only knows how to call it. Of course I use IOC containers like Structuremap to inject the dependencies into the domain. Again I do not state that this is the way DDD recommends to structure your projects, it’s just the way, I architecture my apps. Cheers.

这篇关于DDD:在哪里保留域接口,基础结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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