I’m implementing a subscription to eventstore where we subscribe to all events. It’s set up using something like this:
protected EventStoreSubscriber(IEventStoreConnection connection, Position? position)
{
_connection = connection;
_position = position != null ? position.Value : Position.Start;
_connection.Connected += SetUpSubscription;
}
private void SetUpSubscription(object sender, ClientConnectionEventArgs e)
{
_connection.SubscribeToAllFrom(_position, false, HandleEvent);
}
private void HandleEvent(EventStoreCatchUpSubscription arg1, ResolvedEvent arg2)
{
var eventAndMeta = EventSerialization.DeserializeEvent(arg2.OriginalEvent);
var eventType = eventAndMeta.Event.GetType();
if (_handlers.ContainsKey(eventType))
{
_handlers[eventType](eventAndMeta, arg2.OriginalPosition.Value);
}
_position = arg2.OriginalPosition.Value;
}
There’s one thing I’m a little bit confused about with this code, and that is the fact that OriginalPosition is nullable. When can it be null?