Example #1
0
        public virtual IAggregateRepository <T> GetAggregateRepository <T>(INotificationEventBus bus) where T : IAggregateRoot, new()
        {
            if (typeof(T).GetInterfaces().Contains(typeof(IEventSourced)))
            {
                return(new EventSourcedAggregateRepository <T>(this.EventSerializer, this.EventStore, this.Manifest, new ReadModelBuildingEventBus <T>(this, bus)));
            }

            var repo = new SnapshotAggregateRepository <T>(this.GetSnapshotRepository(typeof(T)), this.Manifest, new ReadModelBuildingEventBus <T>(this, bus));

            if (repo as IObservableRepository != null)
            {
                ((IObservableRepository)repo).Changes.Subscribe(evt => bus.Publish(evt.AsDomainEvent()));
            }

            return(repo);
        }
Example #2
0
        public IList <IReadModelBuilder> GetReadModelBuilders <T>(INotificationEventBus bus) where T : IAggregateRoot, new()
        {
            var result = new List <IReadModelBuilder>();

            if (this.registeredBuilders.ContainsKey(typeof(T)))
            {
                foreach (var factory in this.registeredBuilders[typeof(T)])
                {
                    var repo = factory(this);

                    if (repo as IObservableRepository != null)
                    {
                        ((IObservableRepository)repo).Changes.Subscribe(evt => bus.Publish(evt.AsDomainEvent()));
                    }

                    result.Add(repo);
                }
            }

            return(result);
        }