库之间的调用方法 - 库模式 [英] Call methods between repositories - Repository Pattern

查看:149
本文介绍了库之间的调用方法 - 库模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用存储库模式(如在 http://www.asp.net/mvc 网站的例子)在ASP.NET MVC应用程序。我有两个仓库,一个叫CategoryRepository的另一种叫ProductRepository。我也用两个服务的CategoryService和ProductService验证和调用库方法。我需要在ProductService类别清单,返回一个是在CategoryRepository已实现的方法。我的问题是,这是调用,在CategoryRepository存在从ProductService的ListCategories方法的正确方法是什么?我不想要实现在ProductRepository(DRY哲学)另一种方法ListCategories。谢谢你。

I'm using the Repository Pattern (like the examples in the http://www.asp.net/mvc site) in a ASP.NET MVC application. I have two repositories, one called CategoryRepository an other called ProductRepository. I also use two services, the CategoryService and ProductService to validate and call the repositories methods. I need a list of categories in ProductService, a method that return one is already implemented in the CategoryRepository. My question is, which is the correct way to call the ListCategories method that exists in CategoryRepository from ProductService? I don't want to implement another ListCategories method in the ProductRepository (DRY philosophy). Thanks.

推荐答案

我会推荐滚动类似仓库为一体的服务。因此,如果你创建一个电子商务应用卷起ProductRepository,CategoryRepository等成类似CatalogService的,并将它承载相关的所有信息库。

I would recommend rolling similar repositories into one service. So if you're creating an e-Commerce application roll up ProductRepository, CategoryRepository etc into something like CatalogService and have it host all repositories that are related.

这篇关于库之间的调用方法 - 库模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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