存储库模式是否与Asp.net提供程序模型相同? [英] Is the Repository Pattern the same as the Asp.net Provider Model?

查看:147
本文介绍了存储库模式是否与Asp.net提供程序模型相同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于Asp.net 2.0,有提供者模型。在实现细节上,提供者是派生自ProviderBase的类,它是抽象类而不是接口,但无论如何,提供者模型都在这里,因此我们可以通过编辑web.config来实现交换。例如,如果您创建一个博客应用程序,您可能有一个BlogProvider:ProviderBase,那么您可以使用BlogProvider的实现:SqlBlogProvider,OracleBlogProvider甚至MockBlogProvider进行测试。

Since Asp.net 2.0, there is the Provider Model. On the implementation detail, a provider is class derived from ProviderBase which is an abstract class rather than an interface, but anyway the Provider Model is there so that we can have different implementation to swap in the out by just editing the web.config. For example if you create a blog app, you may have a BlogProvider : ProviderBase, then you can have implementations of BlogProvider like: SqlBlogProvider, OracleBlogProvider and even MockBlogProvider for testing.

现在,Repository Pattern越来越受欢迎,我觉得它是满足同样的需要,尽管在实现细节上,你通常使用接口,所以IBlogProvider,你可以通过构造函数注入不同的实现,而不是属性,但实质上我是不了解这两种模式给我们的区别。

Now, Repository Pattern is getting popular, and I feel it is to satisfy the same need, though in the implementation detail, you normally use interfaces, so IBlogProvider, and you'd inject different implementations through constructors rather than properties, but essentially I don't see the difference in what these 2 patterns gave us.

我个人觉得,提供者模型对我来说更为自然。那么,他们之间有什么区别,或者他们是不同的社区给出的不同的名字是一样的?

Personally, I feel Provider Model is more natural for me in the implementation. So, is there a difference between them or they are just the same thing with different names given by different communities?

感谢任何关于这个的评论,
感谢
Ray。

I'd appreciate any comments on this, Thanks, Ray.

推荐答案

存储库和提供者模式重叠,但它们没有正式描述相同事情。我几乎会说存储库是Provider的一个子集。在实践中,我认为存储库模式是的特定需求 - 抽象化存储库,并在社区中演变成更通用的抽象模式。在这方面,它们已经成为描述相同概念的不同术语。然而,从原始定义来看,它们的范围是不同的:

The Repository and Provider patterns overlap, but they don't formally describe the same thing. I would almost say the Repository is a subset of Provider. In practice, I think the Repository pattern was borne out of a specific need - abstracting repositories - and evolved in the community into a more generic abstraction pattern. In that respect, they have come to be different terms that describe the same concept. However, from the original definitions, they are different in scope:


  • Repository模式的目的是抽象出

  • The purpose of the Repository pattern is to abstract the specifics of a repository of data away from the application.

提供者模式的目的是抽象出任何的细节远离应用程序。这可能是一个数据存储库,但它同样经常是某种逻辑。

The purpose of the Provider model is to abstract the specifics of anything away from the application. This may be a data repository, but it is just as often some kind of logic.

例如,在我们的应用程序中,我们有一个ContextFactoryProvider,它包含用于确定要使用哪个ContextFactory的不同类型的逻辑。在这种情况下,没有数据库;纯粹的应用逻辑需要任意改变;提供者模型允许我们使用单一责任原则将每种逻辑分离成自己的类并轻松地换出这个逻辑。

For example, in our application we have a ContextFactoryProvider, which contains different kinds of logic for determining which ContextFactory to use. There is no repository of data in this case; it's purely application logic that needs to change arbitrarily; the Provider model allows us to use the Single Responsibility Principle to isolate each kind of logic into its own class and swap out that logic easily.

这篇关于存储库模式是否与Asp.net提供程序模型相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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