Can the domain model and repositories be in seperate dlls?

元气小坏坏 提交于 2019-12-04 09:50:12

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.

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