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

发布于 2024-09-12 14:16:22 字数 192 浏览 7 评论 0原文

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

在 3 层架构中,我想我会将领域模型放在业务层中 以及数据访问层中的存储库。

我很困惑,因为我的理解是域模型使用存储库,而存储库应该从域模型返回对象,这会导致循环依赖。

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

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

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

离去的眼神 2024-09-19 14:16:22

我认为您根本不应该让您的域程序集引用您自己的应用程序中的任何内容。它应该是最里面的组件,完全不知道外面的任何事情。它只是坐在那里并了解领域逻辑。

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

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

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

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

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

如果您有任何疑问,请询问。

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.

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.

Ask if you have any questions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文