Skip to content

EventStore (GES) Subscriber With EventDispatcher and Handlers

License

Notifications You must be signed in to change notification settings

gdvalishvili1/EventStore-Subscriber

Repository files navigation

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();
        }
    } 

About

EventStore (GES) Subscriber With EventDispatcher and Handlers

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages