views:

83

answers:

2

Just trying to get some opinions on whether or not CommandHandlers can/should communicate with other CommandHandlers.

Here is a simple case I just ran into. I have a ChangePasswordCommandHandler who's command looks like the following:

public class ChangePasswordCommand : Command
{
    public string Email { get; }
    public string OldPassword { get; set; }
    public string NewPassword { get; set; }
}

So, inside the handler I need to validate the users olds password, so as I see it I have three options:

  1. dispatch out a call to my ValidateCredentialsCommandHandler.
  2. factor out some of the validation logic into a service that both handlers can use.
  3. have the calling process do this check first, but now business logic is leaking outside of my domain layer.

I'm running into a few technical issues with dispatching to other handlers mostly b/c i'm using a transaction per-web request, so i have two transactions trying to contend.

Thoughts?

+2  A: 

Command handler handles command. If ChangePasswordCommandHandler dispatches validation to ValidateCredentialsCommandHandler, what command does ValidateCredentialsCommandHandler handles then?

In short - no, i don't think that makes sense.

2nd option sounds best from ones You mentioned.

Arnis L.
ok, let me try a different scenario. ChangePassword and ResetPassword handlers. it would make sense to have the reset handlers call out to the change password handler, but now they are coupled.thoughts?
Marco
Handler is supposed to handle commands not being called.
Arnis L.
A: 

Thank You for your help everyone.

Marco