onExisting<TCommand extends Object> method
void
onExisting<TCommand extends Object>(
- AggregateIdResolver<
TCommand, TId> toId, - AggregateCommandHandler<
TCommand, TEvent, TValue, TId, TState, TAggregate> action
Register an asynchronous handler for a command, which is expected
to use an existing aggregate instance.
Use parameter toId
to get the AggregateId from give command.
Use parameter action
to performed actions on the aggregate,
given the aggregate instance and the command
- Type parameter
TCommand
- Command type
Implementation
void onExisting<TCommand extends Object>(
AggregateIdResolver<TCommand, TId> toId,
AggregateCommandHandler<TCommand, TEvent, TValue, TId, TState, TAggregate>
action) {
assert(!isFrozen, 'Aggregate handlers has been frozen');
_handlers.putIfAbsent(
typeOf<TCommand>(),
() => RegisteredAggregateCommandHandler<TCommand, TEvent, TValue, TId,
TState, TAggregate>(
ExpectedState.exists,
action,
),
);
_resolvers.putIfAbsent(
typeOf<TCommand>(),
() => (command) => toId(command as TCommand),
);
}