예제 #1
0
 public void BeginReserved(string reservationName, PlusUnitOfWorkOptions options)
 {
     if (!TryBeginReserved(reservationName, options))
     {
         throw new PlusException($"Could not find a reserved unit of work with reservation name: {reservationName}");
     }
 }
예제 #2
0
        public virtual void Initialize(PlusUnitOfWorkOptions options)
        {
            Check.NotNull(options, nameof(options));

            if (Options != null)
            {
                throw new PlusException("This unit of work is already initialized before!");
            }

            Options    = _defaultOptions.Normalize(options.Clone());
            IsReserved = false;
        }
예제 #3
0
        internal PlusUnitOfWorkOptions Normalize(PlusUnitOfWorkOptions options)
        {
            if (options.IsolationLevel == null)
            {
                options.IsolationLevel = IsolationLevel;
            }

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

            return(options);
        }
        private PlusUnitOfWorkOptions CreateOptions(IPlusMethodInvocation invocation, [CanBeNull] UnitOfWorkAttribute unitOfWorkAttribute)
        {
            var options = new PlusUnitOfWorkOptions();

            unitOfWorkAttribute?.SetOptions(options);

            if (unitOfWorkAttribute?.IsTransactional == null)
            {
                options.IsTransactional = _defaultOptions.CalculateIsTransactional(
                    autoValue: !invocation.Method.Name.StartsWith("Get", StringComparison.InvariantCultureIgnoreCase)
                    );
            }

            return(options);
        }
예제 #5
0
        //TODO: More constructors!

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

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

            if (IsolationLevel.HasValue)
            {
                options.IsolationLevel = IsolationLevel;
            }
        }
예제 #6
0
        public IUnitOfWork Begin(PlusUnitOfWorkOptions 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);
        }
예제 #7
0
        public bool TryBeginReserved(string reservationName, PlusUnitOfWorkOptions 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);
        }
예제 #8
0
 public void Initialize(PlusUnitOfWorkOptions options)
 {
     _parent.Initialize(options);
 }