Example #1
0
        /// <summary>Sets the new scope as current using existing current as input.</summary>
        /// <param name="setCurrentScope">Delegate to get new scope.</param>
        /// <returns>Return new current scope.</returns>
        public IScope SetCurrent(SetCurrentScopeHandler setCurrentScope)
        {
            var newCurrentScope = setCurrentScope.ThrowIfNull()(GetCurrentOrDefault());

            _getContextItems()[_currentScopeEntryKey] = newCurrentScope;
            return(newCurrentScope);
        }
Example #2
0
        /// <summary>Changes current scope using provided delegate. Delegate receives current scope as input and  should return new current scope.</summary>
        /// <param name="setCurrentScope">Delegate to change the scope.</param>
        /// <remarks>Important: <paramref name="setCurrentScope"/> may be called multiple times in concurrent environment.
        /// Make it predictable by removing any side effects.</remarks>
        /// <returns>New current scope. So it is convenient to use method in "using (var newScope = ctx.SetCurrent(...))".</returns>
        public IScope SetCurrent(SetCurrentScopeHandler setCurrentScope)
        {
            var oldScope   = GetCurrentOrDefault();
            var newScope   = setCurrentScope.ThrowIfNull()(oldScope);
            var scopeEntry = newScope == null ? null : new ScopeEntry <IScope>(newScope);

            CallContext.LogicalSetData(_currentScopeEntryKey, scopeEntry);
            return(newScope);
        }
Example #3
0
        /// <summary>Sets the new scope as current using existing current as input.</summary>
        /// <param name="setCurrentScope">Delegate to get new scope.</param>
        /// <returns>New current scope.</returns>
        public IScope SetCurrent(SetCurrentScopeHandler setCurrentScope)
        {
            setCurrentScope.ThrowIfNull();

            var scopes = _getContextItems()
                         .ThrowIfNull(Error.Of("No HttpContext is available to set scope to."));

            var oldScope = !scopes.Contains(_currentScopeEntryKey) ? null : scopes[_currentScopeEntryKey] as IScope;

            var newScope = setCurrentScope(oldScope);

            scopes[_currentScopeEntryKey] = newScope;

            return(newScope);
        }
Example #4
0
 /// <summary>Sets the new scope as current using existing current as input.</summary>
 /// <param name="setCurrentScope">Delegate to get new scope.</param>
 /// <returns>Return new current scope.</returns>
 public IScope SetCurrent(SetCurrentScopeHandler setCurrentScope)
 {
     var newCurrentScope = setCurrentScope.ThrowIfNull()(GetCurrentOrDefault());
     _getContextItems()[_currentScopeEntryKey] = newCurrentScope;
     return newCurrentScope;
 }