Accessing domain object state in Upcaster

Hi Guys,

I am facing an issue in writing upcaster for below scenario.


class Example{

private State state;


public void handle(CommandA){

// Newly added code for this revision
if(this.state == something){

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’ve found the ContextAwareEventMultiUpcaster on:
I never tried that and it sound really hard to do.

Is the event needed for a single projection?
If yes, may it be implemented there without an additional event?

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.

Thanks & Regards,

Hi Prasanth,

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?