Setting up a repository pattern in MVC

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 01:56:07
Gordon

Your Repository looks much more like a TableDataGateway to me. The idea of a Repository is to be another layer on top of the mapping layer that mediates between the domain objects and the database. It also serves as an in-memory storage of domain objects (something that is missing from your example) and may encapsulate a Factory for creating new Entities. They often also allow for querying the Repository by Specification patterns:

It's a rather complex pattern. You can find good write-ups about Repository in

Also check Good Domain Driven Design samples

Yes, this is a correct implementation of the Repository pattern. The DAO pattern is often useful as well, but there's nothing wrong with your implementation.

DAO is simple a pattern that separates your persistence logic from your business logic. It would create CRUD operations while your entity would contain methods for your business logic, so it's separating the responsibilites of persistance from your domain. I usually go for DAO for single entities and repositories for aggregates, allowing me to do things like productCatalogRepository.Update(), which in turn will iterate over the product DAOs and have them store themselves.

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