Reputation: 67
I want to ask if it make sense to use the unit of work with repositories on a project following the domain driven design philosophy and clean architecture or it doesn't make more sense and the generic repository pattern is sufficient?
Upvotes: 3
Views: 1951
Reputation: 51323
Martin Fowler describes a Unit of Work as
Maintains a list of objects affected by a business transaction and coordinates the writing out of changes and the resolution of concurrency problems.
The Unit of Work pattern is listed under "Chapter 11: Object-Relational Behavioral Patterns" in his book. Thus it applies to the implementation of a repository.
In DDD you define aggregates and you usually pass the aggregate root to a repository to save it. Now it's up to the repository implementation if it uses a unit of work, because it must coordinate the execution of multiple statements send to the db, or not. Maybe you are using a document oriented NoSQL db and just post the serialized aggregate. In this case you don't have to coordinate actions, because there is only one update action - a put request.
I think that the Unit of Work pattern still makes sense in a clean architecture, but only in the repository implementation.
Upvotes: 9