private void SendAndDeletePending(EventData eventData)
        {
            var ev = new VersionedEventSerializer().Deserialize(eventData);

            _sender.Publish(ev);
            _queue.DeletePending(eventData);
        }
        public AzureEventSourcedRepository(IEventStore <T> eventStore, IEventStoreBusPublisher <T> publisher)
        {
            this._eventStore          = eventStore;
            this._publisher           = publisher;
            _versionedEventSerializer = new VersionedEventSerializer();

            var constructor = typeof(T).GetConstructor(new[] { typeof(Guid), typeof(IEnumerable <IVersionedEvent>) });

            if (constructor == null)
            {
                throw new InvalidCastException(
                          "Type T must have a constructor with the following signature: .ctor(Guid, IEnumerable<IVersionedEvent>)");
            }
            _entityFactory = (id, events) => (T)constructor.Invoke(new object[] { id, events });
        }