Exemplo n.º 1
0
        public IDisposable CreateContext()
        {
            if (this._context != null && !this._context.IsDisposed)
            {
                throw new InvalidOperationException("context exists");
            }

            return(this._context = new EventDispatcherContext());
        }
        public override int SaveChanges(bool acceptAllChangesOnSuccess)
        {
            IEventDispatcherContext dispatcherContext = GetEventDispatcherContext();

            DispatchEvents <IDomainEvent>(dispatcherContext);
            int returnCode = base.SaveChanges(acceptAllChangesOnSuccess);

            DispatchEvents <IIntegrationEvent>(dispatcherContext);
            ClearEvents();
            return(returnCode);
        }
        public override async Task <int> SaveChangesAsync(bool acceptAllChangesOnSuccess, CancellationToken cancellationToken = default(CancellationToken))
        {
            IEventDispatcherContext dispatcherContext = GetEventDispatcherContext();

            await DispatchEventsAsync <IDomainEvent>(dispatcherContext, cancellationToken).ConfigureAwait(false);

            int returnCode = await base.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken).ConfigureAwait(false);

            await DispatchEventsAsync <IIntegrationEvent>(dispatcherContext, cancellationToken).ConfigureAwait(false);

            ClearEvents();
            return(returnCode);
        }
 private Task DispatchEventsAsync <TEvent>(IEventDispatcherContext dispatcherContext, CancellationToken cancellationToken = default(CancellationToken)) where TEvent : IEvent
 {
     return(dispatcherContext.DispatchAsync <TEvent>(cancellationToken));
 }
 private void DispatchEvents <TEvent>(IEventDispatcherContext dispatcherContext) where TEvent : IEvent
 {
     dispatcherContext.Dispatch <TEvent>();
 }