Is the Repository Pattern the same as the Asp.net Provider Model?

烈酒焚心 提交于 2019-12-05 01:30:53

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:

  • 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.

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.

i can't agree with Rex M. The purpose of provider pattern is to provide support for customization via an abstract interface, where as the purpose of repository pattern is to provide a support to abstract the details of undelying database.

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