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()
                    );
            }
        }
        /// <inheritdoc />
        public IUnitOfWorkCompleteHandle Begin(UnitOfWorkOptions options = null)
        {
            if (options == null)
            {
                options = _defaultUowOptions;
            }

            var outerUow = GetCurrentUow();

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

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

            uow.Begin(options);

            SetCurrentUow(uow);

            return(uow);
        }
 private void PerformSyncUow(IInvocation invocation, UnitOfWorkOptions options)
 {
     using var uow = _unitOfWorkManager.Begin(options, requiresNew: false);
     invocation.Proceed();
     uow.Complete();
 }
Example #4
0
 /// <inheritdoc/>
 public UnitOfWork(IServiceProvider serviceProvider, UnitOfWorkOptions options)
 {
     ServiceProvider = serviceProvider;
     Options         = options.Clone();
 }
Example #5
0
 public void Initialize(UnitOfWorkOptions options)
 {
     _parent.Initialize(options);
 }
 /// <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);
        }