Пример #1
0
        protected virtual void InternalDispose()
        {
            if (!_disposed)
            {
                _disposed = true;

                Cleanup.SafeMethod(() => (_container as IDisposable)?.Dispose());
            }
        }
Пример #2
0
            public void Dispose()
            {
                // We do not support a finalizer because MultiInstanceFactory
                // calls Dispose() for us.  It also manages calling Dispose()
                // once and only once.

                Cleanup.SafeMethod(() =>
                {
                    (_weakReference.Target as IDisposable)?.Dispose();
                });
            }
Пример #3
0
        public void Dispose()
        {
            if (_disposed)
            {
                return;
            }

            // We do not support a finalizer because our owner has one
            Cleanup.SafeMethod(() =>
            {
                foreach (var o in _instances)
                {
                    (o as IDisposable)?.Dispose();
                }
            });

            _disposed = true;
        }
Пример #4
0
        public void Dispose()
        {
            // We do not support a finalizer because our owner has one
            if (_disposed)
            {
                return;
            }

            Cleanup.SafeMethod(() =>
            {
                if (_instance.IsValueCreated)
                {
                    (_instance.Value as IDisposable)?.Dispose();
                }
            });

            _disposed = true;
        }
Пример #5
0
        private void Dispose(bool dispose)
        {
            if (_disposed)
            {
                return;
            }

            Cleanup.SafeMethod(() =>
            {
                var trackers = GetTrackers();

                foreach (var t in trackers)
                {
                    t.Dispose();
                }
            });

            _disposed = true;
        }
Пример #6
0
        protected void Dispose(bool dispose)
        {
            if (_disposed)
            {
                return;
            }

            Cleanup.SafeMethod(() =>
            {
                _parent?.RemoveChild(this);

                List <Container> childrenToDispose;

                lock (_syncLock)
                {
                    childrenToDispose = _children.ToList();
                    _children.Clear();
                }

                foreach (var c in childrenToDispose)
                {
                    ((IDisposable)c).Dispose();
                }

                List <IInstanceFactory> factoriesToDispose = _factories.Values.ToList();

                foreach (var f in factoriesToDispose)
                {
                    f.Dispose();
                }

                _factories.Clear();
            });

            _disposed = true;

            if (dispose)
            {
                GC.SuppressFinalize(this);
            }
        }