//https://eventstore.org/blog/20130306/getting-started-part-3-subscriptions/ //SubscribeToAllFrom(this IEventStoreConnection target, // Position? lastCheckpoint, // CatchUpSubscriptionSettings settings, // Action<EventStoreCatchUpSubscription, ResolvedEvent> eventAppeared, // Action<EventStoreCatchUpSubscription> liveProcessingStarted = null, // Action<EventStoreCatchUpSubscription, SubscriptionDropReason, Exception> subscriptionDropped = null, // UserCredentials userCredentials = null) private Action <EventStoreCatchUpSubscription, ResolvedEvent> eventAppeared(Projection projection) => async(_, e) => { // check system events and ignore them... if (e.OriginalEvent.EventType.StartsWith("$")) { return; } // find event type var eventType = EventTypeMapper.GetType(e.Event.EventType); if (eventType == null) { return; } // deserialize the event. var domainEvent = e.Deserialze(); //build your projection await projection.Handle(domainEvent); //store current checkpoint await checkpointStore.SetCheckpoint(e.OriginalPosition.Value, projection); Console.WriteLine($"{domainEvent} projected into {projection}"); };
public static object Deserialze(this ResolvedEvent resolvedEvent) { var dataType = EventTypeMapper.GetType(resolvedEvent.Event.EventType); var jsonData = Encoding.UTF8.GetString(resolvedEvent.Event.Data); var data = JsonConvert.DeserializeObject(jsonData, dataType); return(data); }