/// <summary> /// Get Event as an Observable /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public IObservable <T> GetEvent <T>() { var defered = Observable.Defer(() => { var tuple = _observablesByPayloadType.GetOrAdd(typeof(T), t => { var subject = new Subject <T>(); var removeFromCache = Disposable.Create(() => { Tuple <object, object> _; // throw away object! _observablesByPayloadType.TryRemove(typeof(T), out _); }); // because we are removing items from the cache to clean up on dispose, // we need to publish then refcount the subject to ensure we only // clean up when there are no subscribers left var observable = subject.AddDisposable(removeFromCache) .Publish().RefCount().AsObservable(); return(new Tuple <object, object>(subject, observable)); }); return((IObservable <T>)tuple.Item2); }); return(defered); }
public ActivationStateViewModel(ILog log, IDispatcherSchedulerProvider scheduler) { _log = log; _isActive.ConnectINPCProperty(this, () => IsActive, scheduler).AddDisposable(Disposables); _onInitialise.AddDisposable(Disposables); }
public ClosingStrategy(ILog log) { _log = log; _closing.AddDisposable(Disposables); _closed.AddDisposable(Disposables); CanCloseSetup = () => true; CloseCommand = new DelegateCommand(() => Close()); }