Skip to content

Instantly share code, notes, and snippets.

@Lutando
Created November 8, 2018 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lutando/a6bb6470dd599f2bf5e07901c49bf7e8 to your computer and use it in GitHub Desktop.
Save Lutando/a6bb6470dd599f2bf5e07901c49bf7e8 to your computer and use it in GitHub Desktop.
public class CustomAdapter : DefaultEventAdapter
{
protected override byte[] ToBytes(object @event, JObject metadata, out string type, out bool isJson)
{
var bytes = base.ToBytes(@event, metadata, out type, out isJson);
//Add some additional metadata:
metadata["additionalProp"] = true;
//set the type yourself
switch (@event)
{
case CommittedEvent<UserAccountAggregate, UserAccountId, UserAccountCreatedEvent> s:
type = "UserAccountAggregate.UserAccountCreatedEvent.0";
break;
case CommittedEvent<UserAccountAggregate, UserAccountId, UserAccountNameChangedEvent> s:
type = "UserAccountAggregate.UserAccountNameChangedEvent.0";
break;
}
return bytes;
}
protected override object ToEvent(byte[] bytes, JObject metadata)
{
//Use the metadata to determine if you need to do something additional to the data
//Do something additional with bytes before handing it off to be deserialized.
return base.ToEvent(bytes, metadata);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment