Ejemplo n.º 1
0
        /// <summary>
        /// Invokes the middleware operation.
        /// </summary>
        /// <param name="context">HTTP context</param>
        /// <param name="next">Request delegate</param>
        /// <param name="unitOfWork">An instance of unit of work</param>
        /// <returns></returns>
        protected async Task InvokeAsync(HttpContext context, RequestDelegate next, IUnitOfWork unitOfWork)
        {
            if (_getOrHeadRequestPathsWithoutTransaction != null &&
                (context.Request.Method == WebRequestMethods.Http.Get || context.Request.Method == WebRequestMethods.Http.Head) &&
                _getOrHeadRequestPathsWithoutTransaction.Any(x => x.IsMatch(context.Request.Path.Value)))
            {
                await next.Invoke(context).ConfigureAwait(false);

                return;
            }

            unitOfWork.BeginTransaction(_isolationLevel);

            DomainEvents.ResetDelayedEventsStorage();

            try
            {
                await next.Invoke(context).ConfigureAwait(false);

                await unitOfWork.CommitAsync().ConfigureAwait(false);
            }
            catch
            {
                await unitOfWork.RollbackAsync().ConfigureAwait(false);

                throw;
            }

            DomainEvents.RaiseDelayedEvents();
        }
Ejemplo n.º 2
0
        public async Task BuildAndPersistPolicyEntitiesAndExecuteDomainBehaviourOnThemAndExecuteQueriesOverThem(
            CoreDddSampleNhibernateConfigurator nhibernateConfigurator,
            bool isDelayedDomainEventHandlingEnabled
            )
        {
            var ioCContainer = new WindsorContainer();

            _RegisterComponents(ioCContainer);

            _InitializeDomainEvents(ioCContainer, isDelayedDomainEventHandlingEnabled);

            _RegisterDomainEventHandlers(ioCContainer);

            var unitOfWork = ioCContainer.Resolve <NhibernateUnitOfWork>();

            try
            {
                unitOfWork.BeginTransaction();

                try
                {
                    var shipController         = ioCContainer.Resolve <ShipController>();
                    var policyHolderController = ioCContainer.Resolve <PolicyHolderController>();
                    var policyController       = ioCContainer.Resolve <PolicyController>();

                    await _CreateEntitiesUsingCommands(shipController, policyHolderController, policyController, unitOfWork);
                    await _QueryOverCreatedEntities(policyController);

                    await unitOfWork.CommitAsync();
                }
                catch
                {
                    await unitOfWork.RollbackAsync();

                    throw;
                }

                if (isDelayedDomainEventHandlingEnabled)
                {
                    DomainEvents.RaiseDelayedEvents();
                }
            }
            finally
            {
                ioCContainer.Release(unitOfWork);
            }

            ioCContainer.Dispose();
        }
        public void Context()
        {
            var domainEventHandlerFactory = new FakeDomainEventHandlerFactory(domainEvent => _numberOfHandledDomainEvents++);

            DomainEvents.Initialize(domainEventHandlerFactory, isDelayedDomainEventHandlingEnabled: true);
            DomainEvents.ResetDelayedEventsStorage();

            _entity = new TestEntityWithDomainEvent();
            _entity.BehaviouralMethodWithRaisingDomainEvent();

            DomainEvents.RaiseDelayedEvents();

            DomainEvents.ResetDelayedEventsStorage();
            DomainEvents.RaiseDelayedEvents();
        }
        /// <summary>
        /// Invokes the middleware operation.
        /// </summary>
        /// <param name="context">HTTP context</param>
        /// <param name="next">Request delegate</param>
        /// <param name="unitOfWork">An instance of unit of work</param>
        /// <returns></returns>
        protected async Task InvokeAsync(HttpContext context, RequestDelegate next, IUnitOfWork unitOfWork)
        {
            unitOfWork.BeginTransaction(_isolationLevel);

            DomainEvents.ResetDelayedEventsStorage();

            try
            {
                await next.Invoke(context).ConfigureAwait(false);

                await unitOfWork.CommitAsync().ConfigureAwait(false);
            }
            catch
            {
                await unitOfWork.RollbackAsync().ConfigureAwait(false);

                throw;
            }

            DomainEvents.RaiseDelayedEvents();
        }
Ejemplo n.º 5
0
        private void Application_EndRequest(Object source, EventArgs e)
        {
            if (HttpContext.Current.Server.GetLastError() != null)
            {
                return;
            }

            try
            {
                UnitOfWork.Commit();
            }
            catch
            {
                UnitOfWork.Rollback();
                throw;
            }
            finally
            {
                _unitOfWorkFactory.Release(UnitOfWork);
                UnitOfWork = null;
            }

            DomainEvents.RaiseDelayedEvents();
        }
Ejemplo n.º 6
0
        public void domain_event_is_handled_after_registered_delayed_events_are_raised()
        {
            DomainEvents.RaiseDelayedEvents();

            _raisedDomainEvent.ShouldNotBeNull();
        }
 public void raising_domain_events_is_handled_gracefully()
 {
     DomainEvents.RaiseDelayedEvents();
 }