Can the domain model and repositories be in seperate dlls?

耗尽温柔 提交于 2020-01-01 12:07:18

问题


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.


回答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.



来源:https://stackoverflow.com/questions/3386144/can-the-domain-model-and-repositories-be-in-seperate-dlls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!