/// <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();
         }
     }
 }
Esempio n. 2
0
 /// <summary>
 /// 提交领域仓储工作单元中注册的所有变化。
 /// </summary>
 protected override void DoCommit()
 {
     // 首先我们通过领域事件仓储和事件总线保存并发布事件。
     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);
         }
     }
     // // 然后提交工作单元,完成事件的保存和向事件总线的提交。
     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();
         }
     }
 }
 public void EventStore_SqlExpress_AddDomainEventToStoreTest()
 {
     using (IDomainEventStorage eventStore = application.ObjectContainer.GetService <IDomainEventStorage>())
     {
         var domainEvent = Helper.CreateCreateCustomerDomainEvents()[0];
         eventStore.SaveEvent(domainEvent);
         eventStore.Commit();
     }
 }
Esempio n. 4
0
        public void Commit()
        {
            _domainEventStorage.BeginTransaction();

            foreach (var eventProvider in _eventProviders)
            {
                _domainEventStorage.Save(eventProvider);
                _bus.Publish(eventProvider.GetChanges().Select(x => (object)x));
                eventProvider.Clear();
            }
            _eventProviders.Clear();

            _bus.Commit();
            _domainEventStorage.Commit();
        }