基础架构层中的域驱动设计存储库实现 [英] Domain driven design repository implementation in infrastructure layer

查看:45
本文介绍了基础架构层中的域驱动设计存储库实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对DDD分层体系结构的依赖性有疑问。如果存储库实现在基础结构层中,则意味着基础结构层对域层具有依赖性,因为实体将在存储库实现中被引用。

I got a question on dependencies of DDD layered architecture. If the Repository implementation is in the infrastructure layer, that means that infrastructure layer has a dependency on domain layer because Entities will be referenced in the Repository implementation.

,如果在域中使用基础结构服务,则域层可以引用基础结构层。

On the other side, the Domain layer can have references to the infrastructure layer if infrastructure services are used in the domain.

这是否不会创建循环引用?

Wouldn't this create a cyclic reference?

推荐答案

查看洋葱体系结构显示了DDD解决方案的良好设置。 (请看下面我的评论-如果可以的话,请使用垂直切片-使用多年后洋葱的成本似乎不合理)

Look at the onion architecture it shows a good setup for a DDD solution. (Look at my comment below - use verticial slices instead if you can - cost of onion doesn't seem justified after using for years)

基本上,所有域服务的域模型和接口都被考虑在内核心。层仅取决于位于其上方,更靠近核心的层。它们的实际实现由基础架构处理。

Basically all domain model and interfaces for domain services are considered core. Layers depend only on layers above them that are closer to the core. Their actual implementation is handled by infrastructure.

域项目不应引用基础架构项目。如果域需要使用某些东西,则应将其定义为域内的一个接口,并在基础结构项目中实现。

Domain project shouldn't reference infrastructure project. If domain needs to use something it should be defined as an interface within domain and implemented in the infrastructure project.

最终,您的接口才是定义应用程序的地方。如何实现的逻辑已被外部化。因此,我希望您拥有具有域模型和域服务的程序集,一个前端(例如MVC等)以及一个实现诸如NHibernate之类的基础结构程序集以提供数据等。

Ultimately your interfaces are what defines your application. The logic of how that gets implemented is externalised. So I'd expect you to have assemblies with Domain Models and domain services, a front end (e.g. MVC etc) and then an infrastructure assembly that implements things like NHibernate for providing data etc.

您可以在链接的文章的各个部分中看到实现该体系结构的各种示例。最简单的一个是此处

You can see various samples that implement the architecture in the various parts of the linked article. The simplest one is here

您可以在此处

主要好处最主要的是基础设施方面的问题会最频繁地发生变化。新的数据层技术,新的文件存储等。此外,您的核心域应该相当稳定,因为它没有实现仅通过合同(接口)定义所需内容的任何内容。通过将实现问题放在一个位置,可以最大程度地减少整个程序集所需的更改量。

The main benefit is that it is largely the infrastructural concerns that will change the most often. New data layer technologies, new file storage, etc. Also, your core domain should be reasonably stable as it isn't implementing anything just defining by contract(interfaces) what it requires. By putting the implementation concerns in one location you minimise the amount of changes that will be required across your assemblies.

这篇关于基础架构层中的域驱动设计存储库实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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