Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC: What's the difference in concept between Service and Repository

Tags:

c#

asp.net-mvc

The question I'm asking is kind of subjective. I've seen twice, while exercising with real projects such as StoreFront, both Repository and Services. Sometimes they can just be folders or projects attached to the solution. But they contain classes and interfaces.

So, I'd like to know what goes to the repository and what goes to the services. So far, I was familiar with repositories (we put methods and properties in the repository to reduce the complexity in the controller). How about the services?

So, ASP.NET MVC: What's the difference in concept between Service and Repository? (Maybe none)

My question is Kind of subjective, but I'd like to make sure that I'm not missing anything.

Thanks for helping

like image 270
Richard77 Avatar asked May 10 '10 13:05

Richard77


People also ask

What is the difference between repository and service?

The repository is where the data is stored. The service is what manipulates the data. In a real-world situation comparison, if your money is stored in a vault in a bank, the vault is the repository. The teller that deposits, withdraws, etc is the service.

What is the difference between the repository pattern and a service layer?

Repository layer is implemented to access the database and helps to extend the CRUD operations on the database. Whereas a service layer consists of the business logic of the application and may use the repository layer to implement certain logic involving the database.

What is repository in ASP NET MVC?

The repository is used to create an abstraction layer between the data access layer and the business logic layer of an application. Implementation of repository patterns can help to abstract your application from changes in the data store and can facilitate automated unit testing.

What is Controller service and repository?

@Controller Annotation. @Service annotation is used with classes that provide some business functionalities. @Repository Annotation is used to indicate that the class provides the mechanism for storage, retrieval, update, delete and search operation on objects.


1 Answers

Generally, the repository simply provides an interface to data. There is no application logic there. Services provide interfaces to application logic. Services often use repositories.

like image 103
Tom Cabanski Avatar answered Oct 18 '22 01:10

Tom Cabanski