What is the Difference between Repository and Service Layer in ASP.NET MVC?

Published on May 23, 2013 by abundantcode

Filed under ASP.NET

Last modified May 23, 2013

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 3 (3 votes)

This article have been viewed 3767 times

Repository pattern, Unit of Work and Service Layer is one of the most commonly used word or technique especially when you are working on the ASP.NET MVC project.

What is the Difference between Repository and Service Layer in ASP.NET MVC?

These are the common Design pattern terms used in the ASP.NET MVC project.

The Repository is a layer that provides additional abstraction on the data access class in your project.

For example, you can define a Repository interface which has the common methods like Add, Delete, Get, Get All etc. as shown below.

public interface IRepository<T>

{

IQueryable<T> GetAll();

bool Add(T itemToAdd);

bool Delete(int ItemId);

T Get(int ItemId);

}

In the other hand, the service layer uses the repository layer and in turn includes and exposes additional business logic. Very simple. Isn’t it?

0saves
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

2 Comments

  1. Interesting .NET Links – May 28 , 2013 | TechBlog
    July 2, 2014 - 9:55 pm

  2. Interesting .NET Links – May 24 , 2013 | TechBlog
    September 28, 2014 - 6:02 pm

Leave a Comment


x

You might be Interested in these Posts

How to return Json instead of XML in ASP.NET Web API ?

When you make a call to the ASP.NET Web API action method and notice this in Google Chrome browser ,...

How to Add Web API to existing ASP.NET Web Forms Project ?

In one of the previous posts , we saw how to add the WebAPI to the existing ASP.NET MVC project. Wel...

How to Add Web API to existing ASP.NET MVC Project ?

There are times when you might want to add Web API project to one of your existing ASP.NET MVC proje...