Imagine I am creating a command called UpdatePhoneNumberCommand
. Imagine also that in my application a business rule dictates that no-one may update anyone else's phone number - it is always you updating your own Phone Number.
The number itself obviously needs to go onto the Command as a property (UpdatePhoneNumberCommand.Number
), my question is does the UserId
belong on there too? You could either a) make it a property on the command, figure out who is logged in and then execute the command or b) leave it off the Command then lookup the currently logged-in User
in the CommandHandler
(via some abstraction - IUserContext
or similar).
I don't like the idea of CommandHandler
s being concerned with who is logged-in - even via an abstraction - but I can't really make a convincing case why. It just feels wrong to me - obviously your Handler needs to accept dependencies but I don't feel like figuring out who the subject of a Command is should be looked-up within the Handler.
Do you guys have any advice/heuristics when designing Commands which do something similar?