I am trying to wrap my head around the best way to approach this problem.
I am importing a file that contains bunch of users so I created a handler called
ImportUsersCommandHandler
and my command is ImportUsersCommand
that has List<User>
as one of the parameters.
In the handler, for each user that I need to import I have to make sure that the UserType
is valid, this is where the confusion comes in. I need to do a query against the database, to get list of all possible user types and than for each user I am importing, I want to verify that the user type id
in the import matches one that is in the db.
I have 3 options.
- Create a query
GetUserTypesQuery
and get the rest of this and then pass it on to the ImportUsersCommand as a list and verify inside the command handler - Call the
GetUserTypesQuery
from the command itself and not pass it (command calling another query) - Do not create a
GetUsersTypeQuery
and just do the query results within the command (still a query but no query/handler involved)
I feel like all these are dirty solutions and not the correct way to apply CQRS.