T
- The aggregate root typepublic interface Aggregate<T>
commands
. Implementations of this interface defer the actual handling of commands to a wrapped
instance of type T
or one of its entities.
When a command is dispatched to an aggregate Axon will load the aggregate instance and invoke the related command
handler method. It is rarely necessary to interact with aggregates
directly. Though it is not
recommended it is possible to invoke methods on the wrapped instance using invoke(Function)
and execute(Consumer)
.
Modifier and Type | Method and Description |
---|---|
void |
execute(Consumer<T> invocation)
Execute a method on the underlying aggregate or one of its instances.
|
Object |
handle(Message<?> message)
Handle the given
message on the aggregate root or one of its child entities. |
Object |
identifier()
Get the unique identifier of this aggregate
|
default String |
identifierAsString()
Get the unique identifier of this aggregate, represented as a String.
|
<R> R |
invoke(Function<T,R> invocation)
Invoke a method on the underlying aggregate root or one of its instances.
|
boolean |
isDeleted()
Check if this aggregate has been deleted.
|
Class<? extends T> |
rootType()
Get the class type of the wrapped aggregate root that the Aggregate defers to for command handling.
|
String |
type()
Get the String representation of the aggregate's type.
|
Long |
version()
Get the aggregate's version.
|
String type()
rootType()
unless configured otherwise.default String identifierAsString()
Object identifier()
Long version()
Object handle(Message<?> message) throws Exception
message
on the aggregate root or one of its child entities.message
- The message to be handled by the aggregatenull
if for example handling a
CommandMessage
yields no resultsException
- in case one is triggered during message processing<R> R invoke(Function<T,R> invocation)
execute(Consumer)
to obtain an invocation result, for instance in order to query the aggregate.
Note that the use of this method is not recommended as aggregates are not meant to be queried. Relying on this method is commonly a sign of design smell.
R
- The type of the result produced by the given invocationinvocation
- The function that performs the actual invocationvoid execute(Consumer<T> invocation)
Note that the use of this method is not recommended as the wrapped aggregate instance is not meant to be exposed. Relying on this method is commonly a sign of design smell.
invocation
- The function that performs the invocationboolean isDeleted()
AggregateDeletedException
.true
in case the aggregate was deleted, false
otherwiseCopyright © 2010–2024. All rights reserved.