public override R ExecuteWithResult <R>(Func <R> task, RollbackConfigurationType rollbackConfiguration)
        {
            if (Phase == Phase.NOT_STARTED)
            {
                Start();
            }
            Assert.State(Phase == Phase.STARTED, () => $"The UnitOfWork has an incompatible phase: {Phase}");
            R         result    = default(R);
            Exception exception = null;

            foreach (var processingContext in _processingContexts)
            {
                _processingContext = processingContext;
                try
                {
                    result = task();
                }
                catch (Exception e)
                {
                    if (rollbackConfiguration.RollBackOn(e))
                    {
                        Rollback(e);
                        throw e;
                    }
                    ExecutionResult = Task.FromException <object>(e);
                    exception       = e;
                    continue;
                }
                ExecutionResult = Task.FromResult <object>(result);
            }
            Commit();
            if (exception != null)
            {
                throw exception;
            }
            return(result);
        }
 public BatchingUnitOfWork(List <IMessage> messages)
 {
     Assert.IsFalse(messages.IsEmpty(), () => "The list of Messages to process is empty");
     _processingContexts = messages.Select(x => new MessageProcessingContext(x)).ToList();
     _processingContext  = _processingContexts[0];
 }
Example #3
0
 public DefaultUnitOfWork(IMessage message)
 {
     _processingContext = new MessageProcessingContext(message);
 }