Exemplo n.º 1
1
        public void Execute(IList<IAggregateCommand> commands, int expectedVersion)
        {
            if (commands.Count == 0)
            {
                return;
            }

            // readModelBuilderBus will publish events to a bus that will build read models and then pass events off to
            // the real eventBus
            var readModelBuilderBus = new ReadModelBuildingEventBus(this.registration.ImmediateReadModels(this.scope), this.eventBus);

            // holds the events that were raised from the aggregate and will push them to the read model building bus
            var aggregateEvents = new UnitOfWorkEventBus(readModelBuilderBus);

            // subscribe to the changes in the aggregate and publish them to aggregateEvents
            var aggregateRepo = new AggregateRepository(registration.New, this.scope.GetRegisteredObject<IEventStore>(), scope.GetRegisteredObject<ISnapshotRepository>());
            var subscription = aggregateRepo.Changes.Subscribe(aggregateEvents.Publish);
            this.scope.Add(new UnitOfWorkDisposable(subscription));

            // add them in this order so that aggregateEvents >> readModelBuilderBus >> read model builder >> eventBus
            this.scope.Add(aggregateEvents);
            this.scope.Add(readModelBuilderBus);

            var cmd = new CommandExecutor(aggregateRepo);
            cmd.Execute(commands.ToList(), expectedVersion);

            // enqueue pending commands
            this.EnqueueCommands(this.scope.GetRegisteredObject<IPendingCommandRepository>(), commands);

            // enqueue read models to be built - for non-immediate read models
            var typeName = AggregateRootBase.GetAggregateTypeDescriptor(registration.AggregateType);
            this.EnqueueReadModels(this.scope.GetRegisteredObject<IReadModelQueueProducer>(), typeName, aggregateEvents.GetEvents().Select(x => x.Event).OfType<IAggregateEvent>().ToList());
        }
        public void Execute(IList <IAggregateCommand> commands, int expectedVersion)
        {
            if (commands.Count == 0)
            {
                return;
            }

            // readModelBuilderBus will publish events to a bus that will build read models and then pass events off to
            // the real eventBus
            var readModelBuilderBus = new ReadModelBuildingEventBus(this.registration.ImmediateReadModels(this.scope), this.eventBus);

            // holds the events that were raised from the aggregate and will push them to the read model building bus
            var aggregateEvents = new UnitOfWorkEventBus(readModelBuilderBus);

            // subscribe to the changes in the aggregate and publish them to aggregateEvents
            var aggregateRepo = new AggregateRepository(registration.New, this.scope.GetRegisteredObject <IEventStore>(), scope.GetRegisteredObject <ISnapshotRepository>());
            var subscription  = aggregateRepo.Changes.Subscribe(aggregateEvents.Publish);

            this.scope.Add(new UnitOfWorkDisposable(subscription));

            // add them in this order so that aggregateEvents >> readModelBuilderBus >> read model builder >> eventBus
            this.scope.Add(aggregateEvents);
            this.scope.Add(readModelBuilderBus);

            var cmd = new CommandExecutor(aggregateRepo);

            cmd.Execute(commands.ToList(), expectedVersion);

            // enqueue pending commands
            this.EnqueueCommands(this.scope.GetRegisteredObject <IPendingCommandRepository>(), commands);

            // enqueue read models to be built - for non-immediate read models
            var typeName = AggregateRootBase.GetAggregateTypeDescriptor(registration.AggregateType);

            this.EnqueueReadModels(this.scope.GetRegisteredObject <IReadModelQueueProducer>(), typeName, aggregateEvents.GetEvents().Select(x => x.Event).OfType <IAggregateEvent>().ToList());
        }