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?
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.
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.
A repository handles the data access and the service calls into it after performing any business logic needed.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With