Example #1
0
        private bool TryGetCustomThreadProperties(bool create, out IDictionary <string, object> dict)
        {
            dict = null;
            var state = _contextState.GetState();

            if (state == null && create)
            {
                state = new Dictionary <ModelBase, IDictionary <string, object> >();
                _contextState.SetState(state);
            }

            if (state != null)
            {
                if (!state.TryGetValue(this, out dict))
                {
                    if (create)
                    {
                        dict        = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase);
                        state[this] = dict;
                    }
                }

                return(dict != null);
            }

            return(false);
        }
Example #2
0
        public ILifetimeScope GetLifetimeScope(Action <ContainerBuilder> configurationAction)
        {
            var scope = _state.GetState();

            if (scope == null)
            {
                _state.SetState((scope = BeginLifetimeScope(configurationAction)));
                //scope.CurrentScopeEnding += OnScopeEnding;
            }
            return(scope);
        }
Example #3
0
        public void SetThreadMetadata(string key, object value)
        {
            Guard.NotEmpty(key, nameof(key));

            var state = _contextState.GetState();

            if (state == null)
            {
                state = new Dictionary <string, object>();
                _contextState.SetState(state);
            }

            state[GetContextKey(this, key)] = value;
        }