top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is Repository Pattern in ASP.NET MVC?

+1 vote
502 views
What is Repository Pattern in ASP.NET MVC?
posted Sep 8, 2016 by Jayshree

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

0 votes

Repository pattern is usefult for decoupling entity operations form presentation, which allows easy mocking and unit testing.

“The Repository will delegate to the appropriate infrastructure services to get the job done. Encapsulating in the mechanisms of storage, retrieval and query is the most basic feature of a Repository implementation”

“Most common queries should also be hard coded to the Repositories as methods.”

Source: PoEAA [Fowler] and DDD [Evans]

Which MVC.NET to implement repository pattern Controller would have 2 constructors on parameterless for framework to call, and the second one which takes repository as an input:

class myController: Controller 

private IMyRepository repository; 

public myController(IMyRepository repository) // overloaded constructor 
{ 
this.repository = repository; 
} 

public myController() // default constructor for framework to call 
{ 
myController(new someRepository()); //concreate implementation 
} 
... 

public ActionResult Load() 
{ 
var myData = repository.Load(); // loading data from repository 
} 

} 
answer Sep 9, 2016 by Manikandan J
0 votes

-Repository pattern is used as a default entity operation that allow the decoupling of the components used for presentation.

-Repository pattern allows easy testing in the form of unit testing and mocking.

-Repository pattern will have the proper infrastructure services to be used in the web applications.

-It uses the mechanism of encapsulating that provides storage, retrieval and query for the implementation of the repository.

-Repository patterns are hard coded in the application that is to be used in ASP.NET MVC architecture.

answer Sep 10, 2016 by Shivaranjini
...