We are at the point of our development cycle (asp.net mvc applciation), where we need to make changes to our existing commands and events (for example, adding / removing several properties, etc.).
I am trying to find a way to introduce version control of commands / events in the system. I read a lot of posts about google / stackoverflow etc., but I still see sample code that implements it. Is there a recommended model to follow when managing versioning? If yes, then any examples / snippets?
Edit: this is how far I got with this
- I brought my events back, so that the latter will always be called the same, while those that are outdated will have a suffix added to it, for example, "_V1", "_V2", etc.
So, if I have an event
public class OrderSubmittedEvent : IDomainEvent { public int OrderId { get; private set; } public OrderSubmittedEvent(int orderId) { OrderId = orderId; } }
and if I need to add some properties, rename my event above to
public class OrderSubmittedEvent_V1 : IDomainEvent { public int OrderId { get; private set; } public OrderSubmittedEvent_V1(int orderId) { OrderId = orderId; } }
and enter another event with the same name as my original event, but with added properties, for example
public class OrderSubmittedEvent : IDomainEvent { public int OrderId { get; private set; } public OrderSubmittedEvent(int version = 1, int orderId = 0, string customerName = "Joe blogs", string address = "Earth") { OrderId = orderId; CustomerName = customerName; Address = address; CurrentVersion = version; } public static int LatestVersion { get { return 2; } } public int CurrentVersion { get; set; } public string CustomerName { get; set; } public string Address { get; set; } }
I still need to continue and change my code that publishes this event to include values ββfor new properties.
- any given point in time when I get all my events from the event store (say, for replay), they will always be of the same type after deserialization (in this case OrderSubmittedEvent) with new properties that were not part of the old event, filled with their default values.
While playing back my events, I do my events through IEventUpgrader First it checks to see if the latest version is available. since the type will always be the event type, this check is based on the LastVersion and CurrentVersion properties
What does everyone think of this approach?
next todo
- If the event is an old version, post the UpdateMYEVENT event
thanks