Hi, in my DDD/CQRS/ES app, I have several event handlers that listen to several streams and update a specific readstore view each. Some of those handlers are what I would call stateless, in that they can just update the readstore view with the data that they have and all is well. But a handful collect state which they use to enhance the event as it comes through. So for instance I have a TrainerPayments handler. the TrainerPaid event comes through with
{
trainerId: 123,
appointments:[
appointmentId:123,
]
}
maybe a bit more but the read view wants to see
Bobby Jones was Paid for Appointments:
1/1/2018 | Bubba Smith | 7:30 AM | Down Town Location
etc…
so my handler listens to all relevant appointment events and builds up a list of appointments, a list of clients and builds up a list of clients, locations so on and so forth. The state is persisted in the db or a cache. So then when a TrainerPaid event comes in I can create an entry in the readstore with all the data that the frontend wants to see.
This is basic event enhancing. Some do it before the event is fired by querying the readstore, I do it on the other end so I don’t have to deal with race conditions etc.
So I was wondering if this would be a possible candidate for a projection? Projections can maintain state. It seems like this would work in the same way. The upside being that I wouldn’t have to manage keeping my eventhandler state persisted.
Does this sound plausible?