cqrs
cqrs copied to clipboard
Aggregate event streams
I'm submitting a...
[ ] Regression
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
Persisting events using external stores such as Event Store happens by appending them to a stream. The stream groups all events related to a particular instance of an aggregate root. The stream name usually is <AggregateRoot>-<id>
.
At the moment, the stream name/id information has to be bundled with the event.
Expected behavior
It would be great to introduce the concept of stream name/id at the AggregateRoot
level
export abstract class AggregateRoot<EventBase extends IEvent = IEvent> {
// ...
protected get streamId(): string {
return void 0
}
publish<T extends EventBase = EventBase>(event: T, streamId?: string) {}
}
Such change would also impact
- the
IEventBus
andIEventPublisher
interfaces - the
EventPublisher
If streamId
is optional, the change is non-breaking.
Wrapping the event and passing the streamId as metadata to the event envelope (which also extends IEvent) may solve the problem.
the event handler can be decorated as follow:
@EventsHandler(Envelope<OriginalEvent>)
(just started looking into nestjs and CQRS module... hope I'm not messing up)