I know this is just example, but shouldn’t such logic be placed in a “Repository”?
Mahmoud Tantawy
12

Not really, Repository is meant for pure CRUD operations. While Service are intended to do more. For example, let us consider User Register use case, you may want to have following:

  • Input validation (Front end, will be done by clients)
  • Backend validation: Service layer (called from Controller)
  • Generate the activation key : Service layer
  • Add user in DB: By Repository ( called from service)
  • Queue activation email notification: Service layer

Any of such patterns are not necessary, but if standard patterns are not followed, it will drive you nuts when application grows.