I am facing an issue in writing upcaster for below scenario.
@Aggregate
class Example{
private State state;
@CommandHandler
public void handle(CommandA){ apply(EventA);
// Newly added code for this revision if(this.state == something){ apply(EventB); } }
@EventSourcingHandler public void when(EventA){ //do something }
}
Portion of code snippet marked red above is newly added code for this revision, i want to replay all events to rebuild aggregate. How do get state value in my upcaster code to apply new event?
Please suggest elegant way to handle this scenario.
I tried ContextAwareEventMultiUpcaster, it works. I can upcast and send stream of events.
My problem is to access state value in upcaster. Since, based on state, i have to decide to fire an event or not. This is what I want help on.
an upcaster is not aware of the consumer of the stream it is upcasting for. Therefore, it does not have access to the state of those objects.
I don’t have a full picture of what you’re trying to do, but it feels a bit like a design smell. Upcasters are intended to adjust event structure, not meaning. It feels like you’re trying to make it feel like something happened, that didn’t really happen (at the time).
I’m not sure how complex it is to calculate the state you need to verify against, but can’t you use the context of the ContextAwareUpcasterChain to keep track of that state from the upcaster?