Safe Haskell | None |
---|---|
Language | Haskell2010 |
Defines an Aggregate type-class from DDD parlance.
- data Aggregate state event command = Aggregate {
- aggregateCommandHandler :: state -> command -> [event]
- aggregateProjection :: Projection state event
- allAggregateStates :: Aggregate state event command -> [command] -> [state]
- commandStoredAggregate :: Monad m => EventStore serialized m -> Aggregate state serialized command -> UUID -> command -> m [serialized]
- serializedAggregate :: Aggregate state event command -> Serializer event serializedEvent -> Serializer command serializedCommand -> Aggregate state serializedEvent serializedCommand
Documentation
data Aggregate state event command Source #
An Aggregate
is a combination of a Projection
and a function to
validate commands against that Projection
. When using an aggregate in some
service, it is common to simply load the latest projection state from the
event store and handle the command. If the command is valid then the new
events are applied to the projection in the event store.
Aggregate | |
|
allAggregateStates :: Aggregate state event command -> [command] -> [state] Source #
Given a list commands, produce all of the states the aggregate's projection sees. This is useful for unit testing aggregates.
commandStoredAggregate :: Monad m => EventStore serialized m -> Aggregate state serialized command -> UUID -> command -> m [serialized] Source #
Loads the latest version of a Projection
from the event store and tries to
apply the Aggregate
command to it. If the command succeeds, then this
saves the events back to the store as well.
serializedAggregate :: Aggregate state event command -> Serializer event serializedEvent -> Serializer command serializedCommand -> Aggregate state serializedEvent serializedCommand Source #
Use a pair of Serializer
s to wrap a Aggregate
with event type event
and command type command
so it uses the serializedEvent
and
serializedCommand
types.