I am trying to create a site using the 开发者_运维百科ASP MVC Framework. Some of the documentation use the IRepository pattern to abstract the information being sent to the view for rendering, while others recommend using a ViewModel (as in MVVC).
What is the difference?
Aren't these the same concept?
Thanks in advance
The Repository pattern has more to do with how data is persisted and retrieved from the database, while the ViewModel pattern is a UI pattern that defines how to bind data to the UI. One is at the database level, while one is at the UI level, so they're completely different in that way.
Read this for Repository Pattern, and read this for MVVM.
The Repository and ViewModel patterns work perfectly together: the ViewModel has access to a Repository and the View is bound to ViewModel.
Repository -> ViewModel -> View
Some examples may skip the ViewModel part, but using Repository directly in the View in a real application is a bad idea in the matter of separation of concerns.
精彩评论