Esempio n. 1
0
        /// <summary>
        /// Creates a new connection scope (may or may not be transactional depending on settings).
        /// </summary>
        /// <param name="settings"></param>
        /// <returns></returns>
        public static ConnectionScope NewConnectionScope(ConnectionScopeSettings settings = null)
        {
            if (settings == null)
            {
                settings = new ConnectionScopeSettings();
            }

            var mode = settings.ScopeMode.GetValueOrDefault(Globals.DefaultConnectionScopeMode);

            var ss       = CEF.CurrentServiceScope;
            var useLocal = ss.Settings.ConnectionScopePerThread.GetValueOrDefault(Globals.ConnectionScopePerThread);
            var cs       = new ConnectionScope(settings.IsTransactional.GetValueOrDefault(Globals.UseTransactionsForNewScopes), settings.ConnectionStringOverride, settings.CommandTimeoutOverride);

            if (!useLocal)
            {
                if (mode == ScopeMode.CreateNew || ss._currentConnScope == null)
                {
                    ss.ConnScopeInit(cs, mode);
                }
            }
            else
            {
                if (mode == ScopeMode.CreateNew || _currentConnScope == null)
                {
                    ConnScopeInit(cs, mode);
                }
            }

            return(CurrentConnectionScope);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a new connection scope that is transactional.
        /// </summary>
        /// <param name="settings"></param>
        /// <returns></returns>
        public static ConnectionScope NewTransactionScope(ConnectionScopeSettings settings = null)
        {
            if (settings == null)
            {
                settings = new ConnectionScopeSettings();
            }

            settings.IsTransactional = true;

            return(NewConnectionScope(settings));
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a new connection scope that's transactional and tied to a specific service scope.
        /// </summary>
        /// <param name="relateTo"></param>
        /// <returns></returns>
        public static ConnectionScope NewTransactionScope(ServiceScope relateTo)
        {
            if (relateTo?.Settings == null)
            {
                throw new ArgumentNullException("relateTo");
            }

            var settings = new ConnectionScopeSettings();

            settings.IsTransactional = true;
            relateTo.Settings.ConnectionScopePerThread = false;

            return(NewConnectionScope(settings));
        }