在实现存储库模式时,查找值/表是否应该获得自己的存储库? [英] When implementing the repository pattern should lookup value / tables get their own Repository?

查看:50
本文介绍了在实现存储库模式时,查找值/表是否应该获得自己的存储库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在根据 .

解决方案

没有.存储库应该代表领域模型概念,而不是实体级别的概念,当然也不是数据库级别的.考虑您希望对域的给定组件(例如 Spaces)执行的所有操作.

您需要做的一件事是 GetSpaceCategories().这绝对应该包含在 Spaces 存储库中,因为任何处理 Spaces 的人都希望访问 Space 类别,而无需实例化其他存储库.

我认为通用存储库会适得其反.将存储库视为实用程序类实际上可以保证任何中等复杂的操作都必须实例化两个存储库.

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.

解决方案

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.

这篇关于在实现存储库模式时,查找值/表是否应该获得自己的存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆