Beispiel #1
0
        private void PerformAsyncUow(IInvocation invocation, UnitOfWorkOptions options)
        {
            var uow = _unitOfWorkManager.Begin(options);

            try
            {
                invocation.Proceed();
            }
            catch
            {
                uow.Dispose();
                throw;
            }

            if (invocation.Method.ReturnType == typeof(Task))
            {
                invocation.ReturnValue = InternalAsyncHelper.AwaitTaskWithPostActionAndFinally(
                    (Task)invocation.ReturnValue,
                    async() =>
                {
                    uow.Complete();
                    await Task.FromResult(0);
                },
                    exception => uow.Dispose()
                    );
            }
            else //Task<TResult>
            {
                invocation.ReturnValue = InternalAsyncHelper.CallAwaitTaskWithPostActionAndFinallyAndGetResult(
                    invocation.Method.ReturnType.GenericTypeArguments[0],
                    invocation.ReturnValue,
                    async() =>
                {
                    uow.Complete();
                    await Task.FromResult(0);
                },
                    exception => uow.Dispose()
                    );
            }
        }
Beispiel #2
0
        /// <inheritdoc />
        public IUnitOfWorkCompleteHandle Begin(UnitOfWorkOptions options = null)
        {
            if (options == null)
            {
                options = _defaultUowOptions;
            }

            var outerUow = _currentUnitOfWorkProvider.Current;

            if (options.Scope == TransactionScopeOption.Required && outerUow != null)
            {
                return(new InnerUnitOfWorkCompleteHandle());
            }

            var uow = _iocResolver.Resolve <IUnitOfWork>();

            uow.Begin(options);

            _currentUnitOfWorkProvider.Current = uow;

            return(uow);
        }
 /// <summary>
 /// Can be implemented by derived classes to start UOW.
 /// </summary>
 protected virtual void BeginUow(UnitOfWorkOptions curUowOptions)
 {
 }
        /// <inheritdoc />
        public void Begin(UnitOfWorkOptions options)
        {
            PreventMultipleBegin();

            BeginUow(options);
        }
 /// <inheritdoc />
 public UnitOfWorkCoreOptionsBuilder()
 {
     UowOptions = new UnitOfWorkOptions();
 }