Search code examples
system.reactivereactiveui

MessageBus and Replay


I tried to register to the MessageBus an observable that replay the last value produced when a new subscription occurs

var currentViewObs = currentViewGallery.ObservableForProperty(g => g.SelectedIndex)
                .Value().Select(CurrentViewObsSelector).Replay(1);

currentViewObs.Connect();

MessageBus.Current.RegisterMessageSource(currentViewObs, MessageBusContracts.CurrentView);

This doesn't work because the observable is wrapped in a ScheduledSubject which swallows the replay. Is there another way of doing that?


Solution

  • In this case, you probably want to use your own MessageBus - implement IMessageBus (possibly by just copy-pasting code from here and editing it), then assign it to MessageBus.Current