I’m making my way into using Event Sourcing pattern, and there is one thing that bother me.
What will happen if I change source code for some event handlers, the next time I will be rebuilding object state (replaying events) I might get completly different object, or worse I can get nothing cause of some exceptional condition in one of handlers doing some rule checking.
Does it mean that event handling code should be immutable? (Once you wrote it you never touch it again). I really don’t like this idea.
After not long research and thinking, I came to conclusion that Event is a message and like any message in for example SOA it should be versioned.
I assume we’re discussing implementation of http://www.martinfowler.com/eaaDev/EventSourcing.html in C# 4.0.
Generally speaking, as a library writer, if you make a public method, property, or event, you make a promise to consumers that you won’t go changing it.
If you’d like added flexibility in the type of objects that event delivers, send an arg of type object, and use reflection when handling to decide what you’ve received, and dispatch it properly.
Rule checking and exception propagation can be handled through Calcelable events, or by simply packaging and sending the exception in the arg. But you have to ask yourself — how do these things affect the state of the observed object?