Skip to content

Latest commit

 

History

History
36 lines (31 loc) · 1.23 KB

README.md

File metadata and controls

36 lines (31 loc) · 1.23 KB

EventStore-Subscriber

EventStore (GES) Subscriber With EventDispatcher and Handlers

Example

public class ExampleAggregateCreatedEvent : IStoredEvent
    {
        public ExampleAggregateCreatedEvent(string state)
        {
            State = state;
        }

        public string State { get; }
    }

 //start listening on every stream change, and dispatch deserialized event to every registered eventHandlers like below 
 new CatchUpSubscriptionClient(
                    serviceProvider,
                    eventPositionRepository,
                    unitOfWork,
                    storedEventSerializer,
                    eventDispatcher
                    ).Start(eventStoreConnString,
                    config.GetValue<string>("EventStore:UserName"),
                    config.GetValue<string>("EventStore:Password"));

 //subscribed event stream changes handled here
 public class ExampleEventStoreEventHandler : IHandleStoredEvent<ExampleAggregateCreatedEvent>
    {
        public void Handle(FakeAggregateCreatedEvent @event, StoredEventDispatchContext storedEventDispatchContext)
        {
            //do work like storedEventDispatchContext.ServiceProvider.GetService<SomeRepository>().Save();
        }
    }