Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hey everyone
i am just a beginner,i was learning repository patterns today and i cam across this line of code,and i am not able to understand this line of code
neways my question is
C#
public class HomeController : Controller
{
//
// GET: /Home/
IRepository i1;
public HomeController()
{
i1 = new Repository();
}
public ActionResult Index()
{
return View();
}

i am using a repository pattern, irepository is the interface and repository is the class that implements the interface!
but i am not able to undestand this piece of code written below
C#
i1=new repository();

can you please explain what this LOC is intended to do??
Posted
Updated 12-Apr-14 22:38pm
v2

1 solution

The Repository and Unit of Work Patterns:
The repository and unit of work patterns are intended to create an abstraction layer between the data access layer and the business logic layer of an application. Implementing these patterns can help insulate your application from changes in the data store and can facilitate automated unit testing or test-driven development (TDD).

C#
public HomeController()
{
i1 = new Repository();
}


Explanation: It just instantiates an object of your Repository class.After that you can use that to call your CRUD operations which are implemented in your Repository class.

It's like this :
C#
var students = from s in i1.GetStudents()
                       select s;


Please read this article for more info : Implementing the Repository and Unit of Work Patterns in an ASP.NET MVC Application
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900