public virtual void Delete(T instance)
        {
            this.Repository.Delete(instance);

            var modelChange = NotificationExtensions.CreateModelNotification(instance.Identity, null, ModelChangeKind.Deleted);

            this.changes.OnNext(modelChange);
        }
        public virtual void DeleteId(Guid id)
        {
            this.Repository.DeleteId(id);

            var modelChange = NotificationExtensions.CreateModelNotification(id, null, ModelChangeKind.Deleted);

            this.changes.OnNext(modelChange);
        }
        private IDomainNotification SaveSnapshot(IAggregateRoot instance, int expectedVersion)
        {
            if (this.snapshotRepository != null && this.ShouldSaveSnapshot(instance))
            {
                var snapshot = ((ISnapshotSupport)instance).GetSnapshot();

                // we have to pass expected version if we don't have an event store
                SaveResult saveResult;
                if (this.eventStore == null)
                {
                    saveResult = this.snapshotRepository.Save(snapshot, expectedVersion);
                }
                else
                {
                    saveResult = this.snapshotRepository.Save(snapshot);
                }

                return(NotificationExtensions.CreateModelNotification(instance.Identity, snapshot, saveResult == SaveResult.Added ? ModelChangeKind.Added : ModelChangeKind.Changed));
            }

            return(null);
        }
        public virtual SaveResult Save(T instance)
        {
            var saveResult = this.Repository.Save(instance);

            IDomainNotification modelChange = null;

            switch (saveResult)
            {
            case SaveResult.Added:
                modelChange = NotificationExtensions.CreateModelNotification(instance.Identity, instance, ModelChangeKind.Added);
                break;

            case SaveResult.Updated:
                modelChange = NotificationExtensions.CreateModelNotification(instance.Identity, instance, ModelChangeKind.Changed);
                break;
            }

            if (modelChange != null)
            {
                this.changes.OnNext(modelChange);
            }

            return(saveResult);
        }