Maria Pithia
Maria Pithia

Reputation: 25

what is the use of repository and why do mvc developers create repository?

I have seen in many MVC project concept of Repository but i dont know why many mvc developers use repository.

What is the advantage of creating repository ?

What is the use of repository?

If it improves performance then how it improves performance?

Are there any guidelines to create repository??

Upvotes: 0

Views: 4728

Answers (3)

Mark Shevchenko
Mark Shevchenko

Reputation: 8197

The concept of repositories is referred to DDD.

It is best to read the book about DDD by Eric Evans.

In short, the repository allows you to hide details of loading objects from a database. This is especially useful for complex composite objects.

Upvotes: 4

Ryan
Ryan

Reputation: 746

@lmad, what you described in you guideline is not repository - it's just a view model in context of MVVM pattern. Repository is a pattern for data access logic, where you define your own contract for data access. In C#, for instance, once you defined repository interfaces, then distinct implementations of every interface can be easily changed by each other.
@Maria Pithia, it will be enough for you: msdn - repository description. Hope, this will help.

Upvotes: 0

Imad
Imad

Reputation: 7490

  1. Advantage of using Reository : Clean code, strongly typed view.
  2. Use of Repository: Repository class may expose DB Table structure or it may be view model that can be passed to view to render data.
  3. No performance gain.
  4. Guidelines

    i. Create repository to represent table in database, columns will be properties of that repository.

    ii. Create repository which to bind strongly typed view. Its properties will be all attribute you want to display using view.

Upvotes: 1

Related Questions