0
votes

Going over some really interesting demo CQRS code here commands and handlers are split in to separate interfaces.

public interface CommandHandler<in T>
{
    void Handle(T command);
}

public interface EventHandler<in T>
{
    void Handle(T @event);
}

I am auto-wiring the commands and events, it seems there may be a limitation with membus where it can only wireup CommandHandlers or EventHandlers, but either way it has me thinking:

Given both interfaces have a Handle method, what is the idea of splitting the commands and events in this way, when a single common command/event Handler interface could be used instead?

1

1 Answers

3
votes

The difference is semantic - an event and command are semantically different message types and it can be beneficial to make that difference explicit. The benefits can be both in terms of organization and functionality since each message type may have unique handling requirements.