域模型和存储库可以位于单独的dll中吗? [英] Can the domain model and repositories be in seperate dlls?

查看:76
本文介绍了域模型和存储库可以位于单独的dll中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

域模型和存储库可以放在单独的dll中吗?

Can the domain model and the repositories be in separate dlls?

在3层体系结构中,我想我会将域模型放在业务层$ b $中b和数据访问层中的存储库。

In a 3 tier architecture I guess I would put the domain model in the business layer and the repositories in the data access layer.

我很困惑,因为据我了解,域模型使用存储库,而存储库应从域模型返回对象,这将导致循环依赖。

I get confused as it is my understanding that the domain model uses the repositories while the repositories should return objects from the domain model, which would cause a circular dependency.

我一定会误解上述一个或多个概念。

I must be misunderstanding one or more of the above concepts.

任何澄清将不胜感激,因为这困扰了我一段时间,谢谢。

Any clarification would be greatly appreciated as this has been bothering me for a while, thanks.

推荐答案

我不认为您应该让您的域程序集完全引用您自己的应用程序中的任何内容。它应该是最里面的程序集,它完全不了解外部的任何东西。它只是坐在那里,并且知道域逻辑。

I don't think you should let your domain assembly reference anything from your own application at all. It should be the innermost assembly, that is totally ignorant of anything on the outside. It just sits there and knows the domain logic.

您的域模型不应该使用存储库,应用程序服务应该使用。
(如果域实体实际上需要使用存储库,则应从应用程序服务中注入它。有人会争辩说,虽然这不是必须的-我也这么认为。)

Your domain model shouldn't be using the repositories, the application services should. (If the domain entities actually needs to use a repository, it should be injected from the application services. Some people would argue, that this should not be necessary though - and I think so too).

尝试以这种方式查看它:您拥有一个应用程序服务,这是您的客户端/前端/控制器可以使用域的主要方式。应用程序服务定义可以在应用程序上完成的操作。

Try looking at it this way: Your have an application service which is the primary way your client/frontend/controller can use the domain. The application services defines the operations that can be done on your application.

应用程序服务使用存储库加载它需要处理的域对象,对该域对象调用必要的方法并返回结果(如果操作返回这样的)。该域对应用程序服务或存储库一无所知。

The application service use a repository to load the domain object that it needs to work on, call the necessary method on the domain object and returns the result (if the operations return a such). The domain know nothing about the application service or the repository.

一个开始以这种方式组织应用程序的好方法是看一下以下一系列博客文章: http://jeffreypalermo.com/blog/the-onion-architecture-part-1/

A nice way to get started organizing your application this way, is taking a look at this series of blog posts: http://jeffreypalermo.com/blog/the-onion-architecture-part-1/

再看看依赖注入,它可以帮助您解决其他问题,在您看来,您会有一个循环引用。

And take a look at dependency injection, it can help you solve other problems, where it seems like, you would have a circular reference.

有任何疑问。

这篇关于域模型和存储库可以位于单独的dll中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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