Example #1
0
        protected virtual async Task WithUnitOfWorkAsync(AbpUnitOfWorkOptions options, Func <Task> action)
        {
            using (var scope = ServiceProvider.CreateScope())
            {
                var uowManager = scope.ServiceProvider.GetRequiredService <IUnitOfWorkManager>();

                using (var uow = uowManager.Begin(options))
                {
                    await action();

                    await uow.CompleteAsync();
                }
            }
        }
Example #2
0
        protected virtual TResult WithUnitOfWork <TResult>(AbpUnitOfWorkOptions options, Func <TResult> func)
        {
            using (var scope = ServiceProvider.CreateScope())
            {
                var uowManager = scope.ServiceProvider.GetRequiredService <IUnitOfWorkManager>();

                using (var uow = uowManager.Begin(options))
                {
                    var result = func();
                    uow.Complete();
                    return(result);
                }
            }
        }
Example #3
0
        protected virtual void WithUnitOfWork(AbpUnitOfWorkOptions options, Action action)
        {
            using (var scope = ServiceProvider.CreateScope())
            {
                var uowManager = scope.ServiceProvider.GetRequiredService <IUnitOfWorkManager>();

                using (var uow = uowManager.Begin(options))
                {
                    action();

                    uow.Complete();
                }
            }
        }
Example #4
0
        private AbpUnitOfWorkOptions CreateOptions(PageHandlerExecutingContext context, UnitOfWorkAttribute unitOfWorkAttribute)
        {
            var options = new AbpUnitOfWorkOptions();

            unitOfWorkAttribute?.SetOptions(options);

            if (unitOfWorkAttribute?.IsTransactional == null)
            {
                options.IsTransactional = _defaultOptions.CalculateIsTransactional(
                    autoValue: !string.Equals(context.HttpContext.Request.Method, HttpMethod.Get.Method, StringComparison.OrdinalIgnoreCase)
                    );
            }

            return(options);
        }
Example #5
0
        private AbpUnitOfWorkOptions CreateOptions(ActionExecutingContext context, UnitOfWorkAttribute unitOfWorkAttribute)
        {
            var options = new AbpUnitOfWorkOptions();

            unitOfWorkAttribute?.SetOptions(options);

            if (unitOfWorkAttribute?.IsTransactional == null)
            {
                var abpUnitOfWorkDefaultOptions = context.GetRequiredService <IOptions <AbpUnitOfWorkDefaultOptions> >().Value;
                options.IsTransactional = abpUnitOfWorkDefaultOptions.CalculateIsTransactional(
                    autoValue: !string.Equals(context.HttpContext.Request.Method, HttpMethod.Get.Method, StringComparison.OrdinalIgnoreCase)
                    );
            }

            return(options);
        }
Example #6
0
        protected virtual async Task <TResult> WithUnitOfWorkAsync <TResult>(AbpUnitOfWorkOptions options, Func <Task <TResult> > func)
        {
            using (IServiceScope scope = ServiceProvider.CreateScope())
            {
                IUnitOfWorkManager uowManager = scope.ServiceProvider.GetRequiredService <IUnitOfWorkManager>();

                using (IUnitOfWork uow = uowManager.Begin(options))
                {
                    TResult result = await func();

                    await uow.CompleteAsync();

                    return(result);
                }
            }
        }
Example #7
0
    private AbpUnitOfWorkOptions CreateOptions(IServiceProvider serviceProvider, IAbpMethodInvocation invocation, [CanBeNull] UnitOfWorkAttribute unitOfWorkAttribute)
    {
        var options = new AbpUnitOfWorkOptions();

        unitOfWorkAttribute?.SetOptions(options);

        if (unitOfWorkAttribute?.IsTransactional == null)
        {
            var defaultOptions = serviceProvider.GetRequiredService <IOptions <AbpUnitOfWorkDefaultOptions> >().Value;
            options.IsTransactional = defaultOptions.CalculateIsTransactional(
                autoValue: serviceProvider.GetRequiredService <IUnitOfWorkTransactionBehaviourProvider>().IsTransactional
                ?? !invocation.Method.Name.StartsWith("Get", StringComparison.InvariantCultureIgnoreCase)
                );
        }

        return(options);
    }
Example #8
0
        //TODO: More constructors!

        public virtual void SetOptions(AbpUnitOfWorkOptions options)
        {
            if (IsTransactional.HasValue)
            {
                options.IsTransactional = IsTransactional.Value;
            }

            if (Timeout.HasValue)
            {
                options.Timeout = Timeout;
            }

            if (IsolationLevel.HasValue)
            {
                options.IsolationLevel = IsolationLevel;
            }
        }
Example #9
0
    public IUnitOfWork Begin(AbpUnitOfWorkOptions options, bool requiresNew = false)
    {
        Check.NotNull(options, nameof(options));

        var currentUow = Current;

        if (currentUow != null && !requiresNew)
        {
            return(new ChildUnitOfWork(currentUow));
        }

        var unitOfWork = CreateNewUnitOfWork();

        unitOfWork.Initialize(options);

        return(unitOfWork);
    }
Example #10
0
    public bool TryBeginReserved(string reservationName, AbpUnitOfWorkOptions options)
    {
        Check.NotNull(reservationName, nameof(reservationName));

        var uow = _ambientUnitOfWork.UnitOfWork;

        //Find reserved unit of work starting from current and going to outers
        while (uow != null && !uow.IsReservedFor(reservationName))
        {
            uow = uow.Outer;
        }

        if (uow == null)
        {
            return(false);
        }

        uow.Initialize(options);

        return(true);
    }
Example #11
0
 public void Initialize(AbpUnitOfWorkOptions options)
 {
     _parent.Initialize(options);
 }