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

            options.FillDefaultsForNonProvidedOptions(_defaultOptions);

            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. 2
0
 private void PerformSyncUow(IInvocation invocation, UnitOfWorkOptions options)
 {
     using (var uow = _unitOfWorkManager.Begin(options))
     {
         invocation.Proceed();
         uow.Complete();
     }
 }
Esempio n. 3
0
        /// <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();
        }
Esempio n. 4
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
                    );
            }
        }
Esempio n. 5
0
 private void PerformUow(IInvocation invocation, UnitOfWorkOptions options)
 {
     if (AsyncHelper.IsAsyncMethod(invocation.Method))
     {
         PerformAsyncUow(invocation, options);
     }
     else
     {
         PerformSyncUow(invocation, options);
     }
 }