Exemplo n.º 1
0
 public virtual void Initialize(IUnitOfWorkOptions unitOfWorkOptions)
 {
     Check.NotNull(unitOfWorkOptions, nameof(unitOfWorkOptions));
     if (UnitOfWorkOptions != null)
     {
         throw new XpressException("This unit of work is already initialized before!");
     }
     else
     {
         IsReserved        = false;
         UnitOfWorkOptions = unitOfWorkOptions.Clone();
         if (UnitOfWorkOptions.IsTransactional)
         {
             if (_dbContextProvider.DbContextTransaction == null)
             {
                 var isoLationLevel = UnitOfWorkOptions.IsolationLevel;
                 _dbContextProvider.DbContextTransaction = _dbContextProvider.GetDbContext().Database.BeginTransaction(isoLationLevel);
             }
             else
             {
                 var dbTransaction = _dbContextProvider.DbContextTransaction.GetDbTransaction();
                 _dbContextProvider.GetDbContext().Database.UseTransaction(dbTransaction);
             }
         }
     }
 }
Exemplo n.º 2
0
        private UnitOfWorkOptions CreateOptions(ActionExecutingContext context, UnitOfWorkAttribute unitOfWorkAttribute)
        {
            var unitOfWorkOptions = _defaultUnitOfWorkOptions.Clone();

            unitOfWorkAttribute?.SetOptions(unitOfWorkOptions);

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

            return(unitOfWorkOptions);
        }
Exemplo n.º 3
0
        private UnitOfWorkOptions CreateOptions(IInvocation invocation, [CanBeNull] UnitOfWorkAttribute unitOfWorkAttribute)
        {
            var unitOfWorkOptions = _defaultUnitOfWorkOptions.Clone();

            unitOfWorkAttribute?.SetOptions(unitOfWorkOptions);

            if (unitOfWorkAttribute?.IsTransactional == null)
            {
                unitOfWorkOptions.IsTransactional = !invocation.Method.Name.StartsWith("Get", StringComparison.InvariantCultureIgnoreCase);
            }

            return(unitOfWorkOptions);
        }