Skip to main content

Posts

Showing posts with the label Reactive

Using CompositeDisposable in base classes

To help make an object eligible for collection by the GC (garbage collector) one would implement the IDisposable interface. Executing the dispose methods on muliple implmentations at the correct same time is often done using a custom DisposeWith extension method: 1: public static class DisposableExtensions 2: { 3: public static T DisposeWith<T>( this T disposable, CompositeDisposable disposables) where T : IDisposable 4: { 5: disposables.Add(disposable); 6:   7: return disposable; 8: } 9: } Typically used as follows - explicitly creating a CompositeDisposable instance and then disposing the child view model with the instance: Firstly can I get away without having to explicitly create an instance? Also can I get to a point where I can just do something like this: Inheritance seems the obvious choice but as you might already know, all the disposable types in the System.Rea...