onNew<TCommand extends Object> method
void
onNew<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
create a new 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 onNew<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.notExists,
action,
),
);
_resolvers.putIfAbsent(
typeOf<TCommand>(),
() => (command) => toId(command as TCommand),
);
}