Package io.simplesource.api
Interface CommandHandler<K,C,E,A>
-
- Type Parameters:
K- the aggregate key typeC- all commands for this aggregateE- all events generated for this aggregateA- the aggregate type
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface CommandHandler<K,C,E,A>
A command handler is responsible for accepting or rejecting commands and turning accepted commands into a list of events by applying the appropriate business logic and validations based on the current state. To assist in determining if a command is valid, the command handler has an internal aggregator that parses events as they are generated. The internal aggregator is guaranteed to be fully up-to-date at the point a new command is interpreted with the latest aggregate provided as an argument ready to use for validation and business logic.
-
-
Method Summary
Modifier and Type Method Description io.simplesource.data.Result<CommandError,io.simplesource.data.NonEmptyList<E>>interpretCommand(K key, A currentAggregate, C command)Determine whether you will accept the given command given the current aggregate and, if so, transform it into events.
-
-
-
Method Detail
-
interpretCommand
io.simplesource.data.Result<CommandError,io.simplesource.data.NonEmptyList<E>> interpretCommand(K key, A currentAggregate, C command)
Determine whether you will accept the given command given the current aggregate and, if so, transform it into events.- Parameters:
key- the aggregate key the command applies tocurrentAggregate- the aggregate for this aggregate guaranteed to be up to date with all events seen to datecommand- the command to validate and convert into events- Returns:
- If rejecting, return a failed
Resultproviding one or moreReasonsfor the rejection. If accepting, return one or more events that represent the command.
-
-