示例#1
0
 public void EventStore_MySql_AddDomainEventToStoreTest()
 {
     using (IDomainEventStorage eventStore = application.ObjectContainer.GetService <IDomainEventStorage>())
     {
         var domainEvent = Helper.CreateCreateCustomerDomainEvents()[0];
         eventStore.SaveEvent(domainEvent);
     }
 }
        /// <summary>
        /// Commits the changes registered in the domain repository.
        /// </summary>
        //protected override void DoCommit()
        //{
        //    // firstly we save and publish the event via domain event storage
        //    // and the event bus.
        //    foreach (ISourcedAggregateRoot aggregateRoot in this.SaveHash)
        //    {
        //        if (this.snapshotProvider != null && this.snapshotProvider.Option == SnapshotProviderOption.Immediate)
        //        {
        //            if (this.snapshotProvider.CanCreateOrUpdateSnapshot(aggregateRoot))
        //            {
        //                this.snapshotProvider.CreateOrUpdateSnapshot(aggregateRoot);
        //            }
        //        }
        //        IEnumerable<IDomainEvent> events = aggregateRoot.UncommittedEvents;
        //        foreach (var evt in events)
        //        {
        //            domainEventStorage.SaveEvent(evt);
        //            this.EventBus.Publish(evt);
        //        }
        //    }
        //    // then commit the save/publish via UoW.
        //    if (this.DistributedTransactionSupported)
        //    {
        //        // the distributed transaction is supported either by domain event storage
        //        // or by the event bus. use the MS-DTC (Distributed Transaction Coordinator)
        //        // to commit the transaction. This solves the 2PC for deivces that are
        //        // distributed transaction compatible.
        //        using (TransactionScope ts = new TransactionScope())
        //        {
        //            domainEventStorage.Commit();
        //            this.EventBus.Commit();
        //            if (this.snapshotProvider != null && this.snapshotProvider.Option == SnapshotProviderOption.Immediate)
        //            {
        //                this.snapshotProvider.Commit();
        //            }
        //            ts.Complete();
        //        }
        //    }
        //    else
        //    {
        //        domainEventStorage.Commit();
        //        this.EventBus.Commit();
        //        if (this.snapshotProvider != null && this.snapshotProvider.Option == SnapshotProviderOption.Immediate)
        //        {
        //            this.snapshotProvider.Commit();
        //        }
        //    }
        //}

        protected override async Task DoCommitAsync(CancellationToken cancellationToken)
        {
            // firstly we save and publish the event via domain event storage
            // and the event bus.
            foreach (ISourcedAggregateRoot aggregateRoot in this.SaveHash)
            {
                if (this.snapshotProvider != null && this.snapshotProvider.Option == SnapshotProviderOption.Immediate)
                {
                    if (this.snapshotProvider.CanCreateOrUpdateSnapshot(aggregateRoot))
                    {
                        this.snapshotProvider.CreateOrUpdateSnapshot(aggregateRoot);
                    }
                }
                IEnumerable <IDomainEvent> events = aggregateRoot.UncommittedEvents;
                foreach (var evt in events)
                {
                    domainEventStorage.SaveEvent(evt);
                    this.EventBus.Publish(evt);
                }
            }
            // then commit the save/publish via UoW.
            if (this.DistributedTransactionSupported)
            {
                // the distributed transaction is supported either by domain event storage
                // or by the event bus. use the MS-DTC (Distributed Transaction Coordinator)
                // to commit the transaction. This solves the 2PC for deivces that are
                // distributed transaction compatible.
                using (TransactionScope ts = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                {
                    await domainEventStorage.CommitAsync(cancellationToken);

                    await this.EventBus.CommitAsync(cancellationToken);

                    if (this.snapshotProvider != null && this.snapshotProvider.Option == SnapshotProviderOption.Immediate)
                    {
                        await this.snapshotProvider.CommitAsync(cancellationToken);
                    }
                    ts.Complete();
                }
            }
            else
            {
                await domainEventStorage.CommitAsync(cancellationToken);

                await this.EventBus.CommitAsync(cancellationToken);

                if (this.snapshotProvider != null && this.snapshotProvider.Option == SnapshotProviderOption.Immediate)
                {
                    await this.snapshotProvider.CommitAsync(cancellationToken);
                }
            }
        }
 /// <summary>
 /// Commits the changes registered in the domain repository.
 /// </summary>
 protected override void DoCommit()
 {
     // firstly we save and publish the event via domain event storage
     // and the event bus.
     foreach (var aggregateRoot in this.SaveHash)
     {
         if (this._snapshotProvider != null && this._snapshotProvider.Option == SnapshotProviderOption.Immediate)
         {
             if (this._snapshotProvider.CanCreateOrUpdateSnapshot(aggregateRoot))
             {
                 this._snapshotProvider.CreateOrUpdateSnapshot(aggregateRoot);
             }
         }
         var events = aggregateRoot.UncommittedEvents;
         foreach (var evt in events)
         {
             _domainEventStorage.SaveEvent(evt);
             this.EventBus.Publish(evt);
         }
     }
     // then commit the save/publish via UoW.
     if (this.DistributedTransactionSupported)
     {
         // the distributed transaction is supported either by domain event storage
         // or by the event bus. use the MS-DTC (Distributed Transaction Coordinator)
         // to commit the transaction. This solves the 2PC for deivces that are
         // distributed transaction compatible.
         using (var ts = new TransactionScope())
         {
             _domainEventStorage.Commit();
             this.EventBus.Commit();
             if (this._snapshotProvider != null && this._snapshotProvider.Option == SnapshotProviderOption.Immediate)
             {
                 this._snapshotProvider.Commit();
             }
             ts.Complete();
         }
     }
     else
     {
         _domainEventStorage.Commit();
         this.EventBus.Commit();
         if (this._snapshotProvider != null && this._snapshotProvider.Option == SnapshotProviderOption.Immediate)
         {
             this._snapshotProvider.Commit();
         }
     }
 }
示例#4
0
        /// <summary>
        /// Commits the changes registered in the domain repository.
        /// </summary>
        protected override void DoCommit()
        {
            // firstly we save and publish the event via domain event storage
            // and the event bus.
            foreach (ISourcedAggregateRoot aggregateRoot in this.SaveHash)
            {
                if (this.snapshotProvider != null && this.snapshotProvider.Option == SnapshotProviderOption.Immediate)
                {
                    if (this.snapshotProvider.CanCreateOrUpdateSnapshot(aggregateRoot))
                    {
                        this.snapshotProvider.CreateOrUpdateSnapshot(aggregateRoot);
                    }
                }
                IEnumerable <IDomainEvent> events = aggregateRoot.UncommittedEvents;
                foreach (var evt in events)
                {
                    domainEventStorage.SaveEvent(evt);
                    this.EventBus.Publish(evt);
                }
            }

            // then commit the save/publish via UoW.
            if (this.DistributedTransactionSupported)
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    domainEventStorage.Commit();
                    this.EventBus.Commit();
                    if (this.snapshotProvider != null && this.snapshotProvider.Option == SnapshotProviderOption.Immediate)
                    {
                        this.snapshotProvider.Commit();
                    }
                    ts.Complete();
                }
            }
            else
            {
                domainEventStorage.Commit();
                this.EventBus.Commit();
                if (this.snapshotProvider != null && this.snapshotProvider.Option == SnapshotProviderOption.Immediate)
                {
                    this.snapshotProvider.Commit();
                }
            }
        }
 public void EventStore_SqlExpress_RetrieveAllDomainEventFromStoreTest()
 {
     using (IDomainEventStorage eventStore = application.ObjectContainer.GetService <IDomainEventStorage>())
     {
         foreach (var cce in Helper.CreateCreateCustomerDomainEvents())
         {
             eventStore.SaveEvent(cce);
         }
         //eventStore.Commit();
     }
     using (IDomainEventStorage eventStore = application.ObjectContainer.GetService <IDomainEventStorage>())
     {
         var p = eventStore.LoadEvents(typeof(SourcedCustomer), Helper.AggregateRootId1);
         var q = eventStore.LoadEvents(typeof(SourcedCustomer), Helper.AggregateRootId2);
         var r = eventStore.LoadEvents(typeof(SourcedCustomer), Helper.AggregateRootId3);
         Assert.IsNotNull(p);
         Assert.IsNotNull(q);
         Assert.IsNotNull(r);
         Assert.AreEqual <int>(1, p.Count());
         Assert.AreEqual <int>(1, q.Count());
         Assert.AreEqual <int>(1, r.Count());
     }
 }