/// <summary>
        ///     Afters the processing.
        /// </summary>
        /// <param name="requests">The requests.</param>
        /// <param name="responses">The responses.</param>
        protected override void AfterProcessing(IEnumerable <Request> requests, IEnumerable <Response> responses)
        {
            responses = responses.ToList();
            base.AfterProcessing(requests, responses);
            if (!_validationFailureOccurred)
            {
                var unitOfWork = _unitOfWorkProvider.GetCurrentUnitOfWork();

                unitOfWork.Commit();
            }
        }
        /// <summary>
        ///     Raises the commit event.
        /// </summary>
        /// <typeparam name="TEvent">The type of the event.</typeparam>
        /// <param name="aggregateRoot">The aggregate root.</param>
        /// <param name="commitEvent">The commit event.</param>
        public void RaiseCommit <TEvent> (IAggregateRoot aggregateRoot, TEvent commitEvent) where TEvent : ICommitEvent
        {
            var unitOfWork = _unitOfWorkProvider.GetCurrentUnitOfWork();

            unitOfWork.Register(aggregateRoot, commitEvent);
            Raise(commitEvent);
        }
Example #3
0
        /// <summary>
        ///     Gets the by key.
        /// </summary>
        /// <typeparam name="TAggregate">The type of the aggregate.</typeparam>
        /// <param name="key">The key.</param>
        /// <param name="versionToLoad">The version to load.</param>
        /// <returns>The aggregate.</returns>
        public virtual TAggregate GetByKey <TAggregate> (Guid key, int versionToLoad)
            where TAggregate : class, IAggregateRoot
        {
            var unitOfWork = _unitOfWorkProvider.GetCurrentUnitOfWork();

            if (unitOfWork != null)
            {
                var cachedAggregate = unitOfWork.Get <TAggregate> (key);
                if (cachedAggregate != null)
                {
                    return(cachedAggregate);
                }
            }
            var eventStore = _eventStoreFactory.Build <TAggregate> ();
            var snapshot   = GetSnapshot(eventStore, key, versionToLoad);
            var stream     = OpenStream(eventStore, key, versionToLoad, snapshot);

            if (stream.StreamRevision == 0)
            {
                _streams.Remove(key);
                return(null);
            }

            var aggregate = GetAggregate <TAggregate> (snapshot, stream);

            ApplyEventsToAggregate(versionToLoad, stream, aggregate);

            return(aggregate as TAggregate);
        }
Example #4
0
        public void Execute()
        {
            var systemAccountRepository = IoC.CurrentContainer.Resolve <ISystemAccountRepository> ();
            var systemAccount           = systemAccountRepository.GetByIdentifier(systemAccountIdentifier);

            if (systemAccount == null)
            {
                var systemAdminRole = _roleFactory.Create("System Admin", RoleType.Internal);
                systemAdminRole.AddPermision(SystemAdministrationPermission.SystemAdminPermission);
                systemAdminRole.AddPermision(new Permission {
                    Name = "infrastructuremodule/accessuserinterface"
                });

                systemAccount = new SystemAccount(Guid.Empty, systemAccountIdentifier, new Email(systemAccountIdentifier));
                systemAccount.AddRole(systemAdminRole.Key);

                _unitOfWorkProvider.GetCurrentUnitOfWork().Commit();
            }
        }