Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where do all "bulk" operations belong in DDD?

In DDD one of the key concepts is Repository, which allows you to retrieve Entities (or Aggregate Roots) and then save them back after they are updated.

Let assume that we need to perform some 'bulk' operation with entities, and the number of entities makes it absolutely impossible to retrieve them into memory. I.e. operation can only be performed in the database.

Where is the place for such 'bulk' operation? Should it be a method on repository? Won't it "leak" Repository abstraction with database specific operation? Won't it move business operation from Entity to Repository?

like image 221
alex Avatar asked Feb 18 '09 17:02

alex


1 Answers

I think it should be a service.

Evans recommends in his book, that when you are in doubt whether to put a method that "smells bad" inside a class because you think that it doesn't belong there, make a ServiceFoo class with the operation inside.

like image 111
lurks Avatar answered Oct 03 '22 22:10

lurks