public IUnitOfWorkCompleteHandle Begin(UnitOfWorkOptions options)
        {
            options.FillDefaultsForNonProvidedOptions(_defaultOptions);

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

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

            uow.Completed += (sender, args) =>
            {
                _currentUnitOfWorkProvider.Current = null;
            };

            uow.Failed += (sender, args) =>
            {
                _currentUnitOfWorkProvider.Current = null;
            };

            uow.Disposed += (sender, args) =>
            {
                _iocResolver.Release(uow);
            };

            uow.Begin(options);

            _currentUnitOfWorkProvider.Current = uow;

            return uow;
        }
        /// <summary>
        /// 开始工作单元
        /// </summary>
        /// <param name="options">工作单元选项</param>
        /// <returns></returns>
        /// 这边可以看出只有一个IUnitOfWork对象会被创建, 而且由于这个对象是通过容器直接resolve的,
        /// 那么ABP怎么知道该通过resolve得到什么样的实例呢?是EfUnitOfWork?还是MongoDbUnitOfWork?还是MemoryDbUnitOfWork?还是NhUnitOfWork?
        /// 答案是ABP不知道,ABP作者假设你只会用其中一个模块,所以如果你把这四个module都加入到你的项目中,结果是不可预知的。
        public IUnitOfWorkCompleteHandle Begin(UnitOfWorkOptions options)
        {
            //为未赋值的参数设置默认值
            options.FillDefaultsForNonProvidedOptions(_defaultOptions);

            if (options.Scope == TransactionScopeOption.Required && _currentUnitOfWorkProvider.Current != null)
            {
                //如果当前Scope的设置为Required(而非RequiredNew),并且当前已存在工作单元,那么久返回下面这样的一个对象
                return new InnerUnitOfWorkCompleteHandle();
            }

            //走到这里,表示需要一个新的工作单元,通过IoC创建IUnitOfWork实现对象,然后开始工作单元,并设置此工作单元为当前工作单元
            var uow = _iocResolver.Resolve<IUnitOfWork>();

            uow.Completed += (sender, args) =>
            {
                _currentUnitOfWorkProvider.Current = null;
            };

            uow.Failed += (sender, args) =>
            {
                _currentUnitOfWorkProvider.Current = null;
            };

            uow.Disposed += (sender, args) =>
            {
                _iocResolver.Release(uow);
            };

            uow.Begin(options);

            _currentUnitOfWorkProvider.Current = uow;

            return uow;
        }
Esempio n. 3
0
 private void PerformSyncUow(IInvocation invocation, UnitOfWorkOptions options)
 {
     using (var uow = _unitOfWorkManager.Begin(options))
     {
         invocation.Proceed();
         uow.Complete();
     }
 }
Esempio n. 4
0
 private void PerformUow(IInvocation invocation, UnitOfWorkOptions options)
 {
     if (AsyncHelper.IsAsyncMethod(invocation.Method))
     {
         PerformAsyncUow(invocation, options);
     }
     else
     {
         PerformSyncUow(invocation, options);
     }
 }
        /// <inheritdoc/>
        public void Begin(UnitOfWorkOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            PreventMultipleStart();
            Options = options;
            BeginUow();
        }
        /// <inheritdoc/>
        public void Begin(UnitOfWorkOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            PreventMultipleBegin();
            Options = options; //TODO: Do not set options like that!

            SetFilters(options.FilterOverrides);

            BeginUow();
        }
        public IUnitOfWorkCompleteHandle Begin(UnitOfWorkOptions options)
        {
            if (_currentUnitOfWorkProvider.Current != null)
            {
                return new InnerUnitOfWorkCompleteHandle();
            }

            options.FillDefaultsForNonProvidedOptions(_defaultOptions);

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

            uow.Disposed += (sender, args) =>
                            {
                                _currentUnitOfWorkProvider.Current = null;
                                _iocResolver.Release(uow);
                            };

            uow.Begin(options);

            _currentUnitOfWorkProvider.Current = uow;

            return uow;
        }
        public IUnitOfWorkCompleteHandle Begin(UnitOfWorkOptions options)
        {
            if (_currentUnitOfWorkProvider.Current != null)
            {
                return(new InnerUnitOfWorkCompleteHandle());
            }

            options.FillDefaultsForNonProvidedOptions(_defaultOptions);

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

            uow.Disposed += (sender, args) =>
            {
                _currentUnitOfWorkProvider.Current = null;
                _iocResolver.Release(uow);
            };

            uow.Begin(options);

            _currentUnitOfWorkProvider.Current = uow;

            return(uow);
        }
Esempio n. 9
0
        private void PerformAsyncUow(IInvocation invocation, UnitOfWorkOptions options)
        {
            var uow = _unitOfWorkManager.Begin(options);

            invocation.Proceed();

            if (invocation.Method.ReturnType == typeof(Task))
            {
                invocation.ReturnValue = InternalAsyncHelper.AwaitTaskWithPostActionAndFinally(
                    (Task)invocation.ReturnValue,
                    async () => await uow.CompleteAsync(),
                    exception => uow.Dispose()
                    );
            }
            else //Task<TResult>
            {
                invocation.ReturnValue = InternalAsyncHelper.CallAwaitTaskWithPostActionAndFinallyAndGetResult(
                    invocation.Method.ReturnType.GenericTypeArguments[0],
                    invocation.ReturnValue,
                    async () => await uow.CompleteAsync(),
                    (exception) => uow.Dispose()
                    );
            }
        }
Esempio n. 10
0
        private void PerformAsyncUow(IInvocation invocation, UnitOfWorkOptions options)
        {
            var uow = _unitOfWorkManager.Begin(options);

            invocation.Proceed();

            if (invocation.Method.ReturnType == typeof(Task))
            {
                invocation.ReturnValue = InternalAsyncHelper.AwaitTaskWithPostActionAndFinally(
                    (Task)invocation.ReturnValue,
                    async() => await uow.CompleteAsync(),
                    exception => uow.Dispose()
                    );
            }
            else //Task<TResult>
            {
                invocation.ReturnValue = InternalAsyncHelper.CallAwaitTaskWithPostActionAndFinallyAndGetResult(
                    invocation.Method.ReturnType.GenericTypeArguments[0],
                    invocation.ReturnValue,
                    async() => await uow.CompleteAsync(),
                    (exception) => uow.Dispose()
                    );
            }
        }
Esempio n. 11
0
        private void PerformAsyncUow(IInvocation invocation, UnitOfWorkOptions options)
        {
            var uow = _unitOfWorkManager.Begin(options);

            invocation.Proceed();

            if (invocation.Method.ReturnType == typeof(Task))
            {
                invocation.ReturnValue = InternalAsyncHelper.WaitTaskAndActionWithFinally(
                    (Task)invocation.ReturnValue,
                    async() => await uow.CompleteAsync(),
                    uow.Dispose
                    );
            }
            else //Task<TResult>
            {
                invocation.ReturnValue = InternalAsyncHelper.CallReturnGenericTaskAfterAction(
                    invocation.Method.ReturnType.GenericTypeArguments[0],
                    invocation.ReturnValue,
                    async() => await uow.CompleteAsync(),
                    uow.Dispose
                    );
            }
        }
        private void PerformAsyncUow(IInvocation invocation, UnitOfWorkOptions options)
        {
            var uow = _unitOfWorkManager.Begin(options);

            invocation.Proceed();

            if (invocation.Method.ReturnType == typeof (Task))
            {
                invocation.ReturnValue = AsyncHelper.WaitTaskAndActionWithFinally(
                    (Task) invocation.ReturnValue,
                    async () => await uow.CompleteAsync(),
                    uow.Dispose
                    );
            }
            else
            {
                invocation.ReturnValue = AsyncHelper.CallReturnGenericTaskAfterAction(
                    invocation.Method.ReturnType.GenericTypeArguments[0],
                    invocation.ReturnValue,
                    async () => await uow.CompleteAsync(),
                    uow.Dispose
                    );
            }
        }
Esempio n. 13
0
        /// <inheritdoc/>
        public void Begin(UnitOfWorkOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            PreventMultipleBegin();
            Options = options; //TODO: Do not set options like that, instead make a copy?

            SetFilters(options.FilterOverrides);

            SetTenantId(AbpSession.TenantId);

            BeginUow();
        }
        /// <summary>
        /// 开始工作单元.
        /// </summary>
        /// <inheritdoc/>
        public void Begin(UnitOfWorkOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            //防止Begin被多次调用
            PreventMultipleBegin();
            Options = options; //TODO: Do not set options like that, instead make a copy?

            //过滤配置
            SetFilters(options.FilterOverrides);

            //抽象方法,子类实现
            BeginUow();
        }