NEventStore 3.2.0.0
As far as I found out it is required by NEventStore that old event-types must kept around for event up-conversion.
To keep them deserializing correctly in the future they must have an unique name. It is suggested to call it like EventEVENT_VERSION
.
Is there any way to avoid EventV1
, EventV2
,..., EventVN
cluttering up your domain model and simply keep using Event
?
What are your strategies?
In a question long, long time ago, an answer was missing...
In the discussion referred in the comments, I came up with an - I would say - elegant solution:
Don't save the type-name but an (versioned) identifier
The identifier is set by an attribute on class-level, i.e.
This identifier should get serialized in/beside the payload. In serialized form
"Some.Name.Space.EventSomethingHappened" -> "EventSomethingHappened|0"
When another version of this event is required, the current version is copied in an "legacy" assembly or just in another Namespace and renamed (type-name) to "EventSomethingHappenedV0" - but the
Versioned
-attribute remains untouched (in this copy)In the new version (at the same place, under the same name) just the version-part of the attribute gets incremented. And that's it!
Json.NET supports binders which maps type-identifiers to types and back. Here is a production-ready binder:
...and the
Versioned
-attributeAt last use the versioned binder like this
For a full Json.NET ISerialize-implementation see (an little outdated) gist here:
https://gist.github.com/warappa/6388270