public async Task Start(CancellationToken cancellationToken) { var handlers = _allHandlersResolver(); var types = handlers.Select(h => h.GetType().GenericTypeArguments.Single()); await _eventStream.Start(types); while (cancellationToken.IsCancellationRequested == false) { var eventWrappers = await _eventStream.GetEvents(); foreach (var eventWrapper in eventWrappers) { if (_processEventDelegateCache.ContainsKey(eventWrapper.Event.GetType()) == false) { _processEventDelegateCache.Add(eventWrapper.Event.GetType(), GetProcessEventDelegate(eventWrapper.Event.GetType())); } await _processEventDelegateCache[eventWrapper.Event.GetType()](eventWrapper); } } }