public void OnNext(SubscriptionMessage value)
        {
            //Check if this event passes through the filter
            if (_filter != null && !_filter.DoesEventPassFilter(value.Type, value.SourceStreamId))
            {
                return;
            }

            if (!(value.Event is TEvent typedEvent))
            {
                return;
            }

            using (var scope = _serviceProvider.CreateScope())
            {
                var handler = scope.ServiceProvider.GetService <IPartitionedProjectionEventHandler <TProjection, TEvent> >();
                if (handler == null)
                {
                    return;
                }

                var repository          = scope.ServiceProvider.GetRequiredService <IPartitionedProjectionStateRepository <TProjection> >();
                var partitionIdSelector = scope.ServiceProvider.GetService <IPartitionedProjectionPartitionIdSelector <TProjection, TEvent> >();
                var readModelId         = typedEvent.AggregateId;
                if (partitionIdSelector != null)
                {
                    var partitionIdSelection = partitionIdSelector.GetPartitionId(typedEvent);
                    partitionIdSelection.Wait();
                    readModelId = partitionIdSelection.Result;
                }

                var readModelQuery = repository.GetProjectionState(readModelId);
                readModelQuery.Wait();

                var readModel = readModelQuery.Result;
                if (readModel == null)
                {
                    readModel = new TProjection();
                }

                var projectionTask = handler.ProjectEvent(readModel, typedEvent);
                projectionTask.Wait();
                projectionTask.Result.LastEventId = value.Event.EventId;

                var updateTask = repository.SetProjectionState(readModelId, projectionTask.Result);
                updateTask.Wait();
            }
        }
        public void OnNext(SubscriptionMessage value)
        {
            //Check if this event passes through the filter
            if (_filter != null && !_filter.DoesEventPassFilter(value.Type, value.SourceStreamId))
            {
                return;
            }

            if (!(value.Event is TEvent typedEvent))
            {
                return;
            }

            using (var scope = _serviceProvider.CreateScope())
            {
                var handler = scope.ServiceProvider.GetService <ISubscriptionEventHandler <TProfile, TEvent> >();
                if (handler == null)
                {
                    return;
                }

                handler.HandleEvent(typedEvent).Wait();
            }
        }