public void InvokeHandlers(object message, bool allowMultipleHandlers) { using (_container.RequireScope()) //Use the existing scope when running in an endpoint and create a new one if running in the web { using (var transactionalScope = _container.BeginTransactionalUnitOfWorkScope()) { var handlers = _handlersResolver.GetHandlers(message).ToArray(); try { if (!allowMultipleHandlers) { AssertThatThereIsExactlyOneRegisteredHandler(handlers, message); } foreach (var messageHandlerReference in handlers) { messageHandlerReference.Invoke(message); } transactionalScope.Commit(); } finally { handlers.ForEach(_container.Release); } } } }
public void PopulateEntities(params Guid[] aggregateRootIds) { _logger.Initialize(aggregateRootIds.Length); Parallel.ForEach( aggregateRootIds, entityId => { try { using (_container.BeginScope()) { using (var unitOfWork = _container.BeginTransactionalUnitOfWorkScope()) { _container.ResolveAll <IViewModelPopulator>() .ForEach(populator => populator.Populate(entityId)); unitOfWork.Commit(); } } _logger.LogAggregateHandled(entityId); } catch (Exception e) { _logger.LogError(e, entityId); } }); }
public static void ExecuteUnitOfWork(this IWindsorContainer me, Action action) { using (var transaction = me.BeginTransactionalUnitOfWorkScope()) { action(); transaction.Commit(); } }
public static TResult ExecuteUnitOfWork <TResult>(this IWindsorContainer me, Func <TResult> function) { TResult result; using (var transaction = me.BeginTransactionalUnitOfWorkScope()) { result = function(); transaction.Commit(); } return(result); }
public virtual CommandResult Execute <TCommand>(TCommand command) { var result = new CommandResult(); #pragma warning disable 612,618 using (DomainEvent.RegisterShortTermSynchronousListener <IDomainEvent>(result.RegisterEvent)) #pragma warning restore 612,618 { using (var transaction = _container.BeginTransactionalUnitOfWorkScope()) { if (command is CompositeCommand) { foreach (var subCommand in (command as CompositeCommand).GetContainedCommands()) { try { ExecuteSingle((dynamic)subCommand.Command); } catch (DomainCommandValidationException exception) { var failedException = new DomainCommandValidationException(exception.Message, exception.InvalidMembers .Select(invalidMember => subCommand.Name + "." + invalidMember) .ToList()); throw failedException; } } } else { ExecuteSingle(command); } transaction.Commit(); } return(result); } }