域模型和存储库可以位于单独的 dll 中吗?
域模型和存储库可以位于单独的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您根本不应该让您的域程序集引用您自己的应用程序中的任何内容。它应该是最里面的组件,完全不知道外面的任何事情。它只是坐在那里并了解领域逻辑。
您的域模型不应该使用存储库,应用程序服务应该使用存储库。
(如果域实体实际上需要使用存储库,则应从应用程序服务注入它。有些人会争辩说,这不是必需的 - 我也这么认为)。
尝试这样看:您有一个应用程序服务,这是您的客户端/前端/控制器使用域的主要方式。应用程序服务定义了可以在您的应用程序上执行的操作。
应用程序服务使用存储库来加载它需要处理的域对象,在域对象上调用必要的方法并返回结果(如果操作返回这样的结果)。该域对应用程序服务或存储库一无所知。
以这种方式开始组织应用程序的一个好方法是查看本系列博客文章: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.