0

So I have a method that receives an array of ids of a given entity in our database, I search in the db for those ids, and the ones that were not found I store them in DB, after that I return an array of those entities containing the ones that were already created and the new ones.

Since this entity has relations with a diversity of other entities, this logic is expected to be consumed by many command/query handlers, where should I put this logic?

  • Create a service file that will be imported and called from each domain query/command handler?
  • Create a command-handler doing this logic and call this command-handler from the other hanlders ( i think this is an anti-pattern right? )?
Matheus Hatje
  • 987
  • 1
  • 7
  • 18

1 Answers1

1

I would definitely create a class which encapsulates your logic and inject this class in the command/query handlers.

At first glance, maybe creating a repository class for this entity would be great too, you could encapsulate this logic there.

Erkin Kurt
  • 652
  • 6
  • 16