Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is a Repository still a Repository without Unit of Work?

If you create a repository class that encapsulates all of your persistence logic for a given entity, such as PersonRepository, but your repository class does not implement the Unit of Work pattern or the Identity Map pattern, is it still considered a repository? In other words, are Unit of Work and Identity Map required for a repository implementation, or can we just call any class that encapsulates our persistence logic a repository?

I should add one thing. If a repository does not require these patterns and it's really just a container for persistence methods, then what is the difference between a repository and a DAO (Data Access Object)? Are we just creating multiple names for the same object or are we missing part of what a repository is supposed to be?

like image 665
Rudy Lacovara Avatar asked Apr 24 '09 19:04

Rudy Lacovara


People also ask

Is Unit of Work necessary?

The only reason to still have a unit of work is if you: want to include non-EF-datasources in an atomic data operation. want to use a unit of work in your domain without relying on an EF dependency on that layer.

What is repository Unit of Work?

Unit of Work in the Repository Pattern To say it in simple words, it means that for a specific user action (say registration on a website), all the transactions like insert/update/delete and so on are done in one single transaction, rather then doing multiple database transactions.

What is the difference between a service and a repository?

A repository handles the data access and the service calls into it after performing any business logic needed.

Is DbContext Unit of Work?

The Entity Framework DbContext class is based on the Unit of Work and Repository patterns and can be used directly from your code, such as from an ASP.NET Core MVC controller. The Unit of Work and Repository patterns result in the simplest code, as in the CRUD catalog microservice in eShopOnContainers.


2 Answers

Yes, it is still a repository.

As for if Repository == DAO, I think Repository should be on business logic layer and DAO should be on data access layer, i.e. I think they are on different layers. So as I understand, Repository calls DAO methods to load and persist data.

like image 81
nightcoder Avatar answered Sep 19 '22 03:09

nightcoder


I'd say the Repository and Unit of Work patterns are orthogonal.

Very frequently, I want a single unit of work to span operations on multiple repositories, so an implementation of that would belong into a higher layer.

like image 34
millimoose Avatar answered Sep 22 '22 03:09

millimoose