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

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?