When implementing the repository pattern should lookup value / tables get their own Repository?

蓝咒 提交于 2019-12-11 02:20:23

问题


I am creating RESTful services for several database entities based on a modified version of the BISDM. Some of these entities have associated lookup tables, such as depicted below:

I have decided to use the repository pattern to provide a clean separation between data persistance / retrieval; however, I am not sure how lookups ( as opposed to entities ) should be represented in the repository.

Should lookups get their own repository interface, "share" one with the associated entity, or should there be a generic ILookupRepository interface?

For the moment, these lookups are read-only; however, there will be a time where we may want to edit the lookups via services.

Option 1:
   ISpaceRepository.GetSpaceCategoryById(string id);
Option 2:
   ISpaceCategoryRepository.GetById(string id);
Option 3:
   ILookupRepository.GetSpaceCategoryById(string id);

Incidentally, this question is related to another one regarding look-up tables & RESTful web services.


回答1:


No. Repositories should represent domain model concepts, not entity level concepts, and certainly not database level. Think about all the things you would want to do with a given component of your domain, for example, Spaces.

One of the things that you'll want to do, is GetSpaceCategories(). This should definitely be included in the Spaces repository, as anyone dealing with Spaces will want access to the Space categories without having to instantiate some other repository.

A generic repository would be fairly counter-productive I would think. Treating a repository like a utility class would virtually guarantee that any moderately complex operation would have to instantiate both repositories.



来源:https://stackoverflow.com/questions/1168430/when-implementing-the-repository-pattern-should-lookup-value-tables-get-their

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