/// <summary>
        /// Creates a transaction scope.
        /// </summary>
        public ITransactionScope CreateTransactionScope(DbTransactionScopeOption option = DbTransactionScopeOption.Required)
        {
            var isolationLevel = DbTransactionScope.GetDefaultIsolationLevel();

            var typeName = Configuration.Transaction.Type;

            if (typeName.HasValue())
            {
                Type type  = null; // this is a workaround.
                var  dummy = typeof(DbTransactionScope);
                if (dummy.AssemblyQualifiedName.StartsWith(typeName))
                {
                    type = dummy;
                }
                else
                {
                    type = Type.GetType(typeName);
                }

                if (type == null)
                {
                    throw new Exception("Cannot load type: " + typeName);
                }

                return((ITransactionScope)type.CreateInstance(isolationLevel, option));
            }

            // Fall back to TransactionScope:
            var oldOption = option.ToString().To <TransactionScopeOption>();

            return(new TransactionScopeWrapper(isolationLevel.ToString().To <IsolationLevel>().CreateScope(oldOption)));
        }
Beispiel #2
0
        public DbTransactionScope(IsolationLevel isolationLevel, DbTransactionScopeOption scopeOption = DbTransactionScopeOption.Required)
        {
            IsolationLevel = isolationLevel;
            ScopeOption    = scopeOption;
            Parent         = Root;
            Current        = this;

            if (Root == null)
            {
                Root = this;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Creates a transaction scope.
        /// </summary>
        public static ITransactionScope CreateTransactionScope(DbTransactionScopeOption option = DbTransactionScopeOption.Required)
        {
            var isolationLevel = Config.Get("Default.Transaction.IsolationLevel", System.Data.IsolationLevel.Serializable);

            var typeName = Config.Get <string>("Default.TransactionScope.Type");

            if (typeName.HasValue())
            {
                var type = Type.GetType(typeName);
                if (type == null)
                {
                    throw new Exception("Cannot load type: " + typeName);
                }

                return((ITransactionScope)type.CreateInstance(new object[] { isolationLevel, option }));
            }

            // Fall back to TransactionScope:
            var oldOption = option.ToString().To <TransactionScopeOption>();

            return(new TransactionScopeWrapper(isolationLevel.ToString().To <IsolationLevel>().CreateScope(oldOption)));
        }
Beispiel #4
0
 public DbTransactionScope(DbTransactionScopeOption scopeOption) : this(GetDefaultIsolationLevel(), scopeOption)
 {
 }