ReactiveUI provides you with WhenActivated to help manage lifecycle and the Reactive Extensions provides several different implementations of the IDisposable interface to help you with managing lifetime, scope and resources.
- It is one of the most useful disposables
- What's useful about it is that when you set the disposable, the previous one is Disposed
- Any time you have to manage something where only one can be alive at a time
- Or if you set it to Disposable.Empty, zero or one of something
- It's also atomic aka thread safe, and immune to double-disposing
See this tweet thread https://twitter.com/paulcbetts/status/1034168666739200000?s=19
For a full rundown of each of the implementations see the Disposables