You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there any sort of mechanism within the Messengers to allow for covariant/contravariant subscriptions?
In one of my projects I have been looking into using an EventAggregator, and so far my current solution is using Reactive Extension's Subject<object> to allow for contravariant subscriptions by using the OfType<T>() extension method to filter the Subject. Lets say we have a few events defined like so:
If I wanted to subscribe to all Events, I can use RX as such:
publicSubject<Event>Subject{get;}=new();// SubscribeSubject.OfType<Event>.Subscribe(e =>{/* handle event */});Subject.OnNext(newSpecificEvent());// Invokes handler above, SpecificEvent is covariant to Event
However, it appears that the messengers in MVVM toolkit do not have this behaviour:
WeakReferenceMessenger.Default.Register<Event>(this, e =>{/* handle event */});WeakReferenceMessenger.Default.Send(newSpecificEvent());// DOES NOT raise above handler
The IRecipient<T> interface does not appear to work either for this situation.
Is there currently any way in the toolkit to allow covariant/contravariant subscriptions to messages?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello!
Is there any sort of mechanism within the Messengers to allow for covariant/contravariant subscriptions?
In one of my projects I have been looking into using an EventAggregator, and so far my current solution is using Reactive Extension's
Subject<object>
to allow for contravariant subscriptions by using theOfType<T>()
extension method to filter the Subject. Lets say we have a few events defined like so:If I wanted to subscribe to all
Event
s, I can use RX as such:However, it appears that the messengers in MVVM toolkit do not have this behaviour:
The
IRecipient<T>
interface does not appear to work either for this situation.Is there currently any way in the toolkit to allow covariant/contravariant subscriptions to messages?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions