Dispose() public méthode

public Dispose ( ) : void
Résultat void
        public void Dispose()
        {
            using (var token = @lock.ForReadingUpgradeable())
            {
                if (cache == null)
                {
                    return;
                }
                token.Upgrade();
                cache.Dispose();
                cache = null;

                if (parentScope != null)
                {
                    SetCurrentScope(parentScope);
                }
                else
                {
                    CallContext.FreeNamedDataSlot(keyInCallContext);
                }
            }
#if DOTNET35
            lock (cacheLocker)
            {
                appDomainLocalInstanceCache.Remove(contextId);
            }
#else
            CallContextLifetimeScope @this;
            appDomainLocalInstanceCache.TryRemove(contextId, out @this);
#endif
        }
Exemple #2
0
        public void Dispose()
        {
            using (var token = @lock.ForReadingUpgradeable())
            {
                // Dispose the burden cache
                if (cache == null)
                {
                    return;
                }
                token.Upgrade();
                cache.Dispose();
                cache = null;

                // Restore the parent scope (if inside one)
                if (parentScope != null)
                {
                    SetCurrentScope(parentScope);
                }
                else
                {
#if FEATURE_REMOTING
                    CallContext.FreeNamedDataSlot(callContextKey);
#endif
                }
            }

            CallContextLifetimeScope @this;
            allScopes.TryRemove(contextId, out @this);
        }
		private void EndCurrentScope(ScopeCache scopeCache)
		{
			var scopes = GetCurrentScopes();

			if (scopes.Peek() != scopeCache)
			{
				throw new InvalidOperationException(
					"The scope is not current.  Did you forget to end a child scope?");
			}

			scopeCache.Dispose();
			scopes.Pop();
		}
 public void Dispose()
 {
     using (var token = @lock.ForReadingUpgradeable())
     {
         if (cache == null)
         {
             return;
         }
         token.Upgrade();
         cache.Dispose();
         cache = null;
         SetCurrentScope(parentScope);
     }
 }
		private IScopeCache GetCache(CreationContext.ResolutionContext selected)
		{
			var stash = (IScopeCache)selected.Context.GetContextualProperty("castle-scope-stash");
			if (stash == null)
			{
				var newStash = new ScopeCache();
				var decorator = new ScopeCacheDecorator(newStash);
				decorator.OnInserted += (_, b) =>
				{
					if (b.RequiresDecommission)
					{
						selected.Burden.RequiresDecommission = true;
						selected.Burden.GraphReleased += burden => newStash.Dispose();
					}
				};
				selected.Context.SetContextualProperty("castle-scope-stash", newStash);
				stash = decorator;
			}
			return stash;
		}
Exemple #6
0
        private IScopeCache GetCache(CreationContext.ResolutionContext selected)
        {
            var stash = (IScopeCache)selected.Context.GetContextualProperty("castle-scope-stash");

            if (stash == null)
            {
                var newStash  = new ScopeCache();
                var decorator = new ScopeCacheDecorator(newStash);
                decorator.OnInserted += (_, b) =>
                {
                    if (b.RequiresDecommission)
                    {
                        selected.Burden.RequiresDecommission = true;
                        selected.Burden.GraphReleased       += burden => newStash.Dispose();
                    }
                };
                selected.Context.SetContextualProperty("castle-scope-stash", newStash);
                stash = decorator;
            }
            return(stash);
        }
Exemple #7
0
        public void Dispose()
        {
            using (var token = @lock.ForReadingUpgradeable())
            {
                if (cache == null)
                {
                    return;
                }
                token.Upgrade();
                cache.Dispose();
                cache = null;

                if (parentScope != null)
                {
                    CallContext.SetData(contextKey, parentScope);
                }
                else
                {
                    CallContext.FreeNamedDataSlot(contextKey);
                }
            }
        }