public void Dispose() { EnsureNotDisposed(); if (this != _scopeProvider.AmbientScope) { #if DEBUG_SCOPES var ambient = _scopeProvider.AmbientScope; Logging.LogHelper.Debug <Scope>("Dispose error (" + (ambient == null ? "no" : "other") + " ambient)"); if (ambient == null) { throw new InvalidOperationException("Not the ambient scope (no ambient scope)."); } var infos = _scopeProvider.GetScopeInfo(ambient); throw new InvalidOperationException("Not the ambient scope (see current ambient ctor stack trace).\r\n" + infos.CtorStack); #else throw new InvalidOperationException("Not the ambient scope."); #endif } var parent = ParentScope; _scopeProvider.AmbientScope = parent; // might be null = this is how scopes are removed from context objects #if DEBUG_SCOPES _scopeProvider.Disposed(this); #endif if (parent != null) { parent.ChildCompleted(_completed); } else { DisposeLastScope(); } _disposed = true; GC.SuppressFinalize(this); }
public void Dispose() { EnsureNotDisposed(); if (this != _scopeProvider.AmbientScope) { throw new InvalidOperationException("Not the ambient scope."); } #if DEBUG_SCOPES _scopeProvider.Disposed(this); #endif if (_database != null) { _database.Dispose(); } _scopeProvider.SetAmbient(null); _disposed = true; GC.SuppressFinalize(this); }