public void RegisterForDisposal(IDisposable disposable) { if (_disposables == null) { _disposables = new QueueLite <IDisposable>(); } _disposables.Enqueue(disposable); }
void DisposeAndNotify() { if (_disposables == null || _disposables.Count == 0) { return; } // Make sure the Dispose method for every disposable instances is only called once. while (_disposables.Count > 0) { var disposable = _disposables.Dequeue(); disposable.Dispose(); } _disposables.Discard(); _disposables = null; LifetimeScopeEnded.Invoke(GetLifetimeScopeEndedEventArgs()); }