15

Closed

SubscriptionToken should implement IDisposable

description

This would make it substantially easier to unsubscribe. I just need to dispose the subscription.
 
All in all, I'd align the entire event aggregator with IObservable/IObserver, to make it future-proof to the Reactive Extensions. Implementing IDisposable is just one tiny bit of it.
Closed Oct 25, 2012 at 5:12 PM by DCherubini
Hi,As mentioned before, since Prism v4.1 the SubscriptionToken class implements the IDisposable interface. Hence, as this suggestion is already addressed, we are closing this work item.For those who want the IDisposable pattern to be implemented in other parts of the Prism Library, you can vote or post your suggestion in the following work item: - IDisposable pattern applied to applicable areas of the framework ... (http://compositewpf.codeplex.com/workitem/7117)Regards,Damian Cherubinihttp://blogs.southworks.net/dcherubini

comments

dcazzulino wrote Sep 9, 2010 at 3:25 AM

Since the SubscriptionToken is instantiated by the EventBase itself, nothing would prevent it from passing itself to the token, so that upon disposing the token, it would know which event to call Unsubscribe on.

This is the way Rx extensions do it already, and the intended usage of IObservable.Subscribe.

I'd strongly encourage the team to look for potential refactorings that will make event aggregator Rx-compatible and IObservable/IObserver-based. The current APIs look a little dated with what's coming out of Rx...

fantivero wrote Sep 16, 2010 at 3:07 AM

See more information related information to this in the following thread:
http://compositewpf.codeplex.com/Thread/View.aspx?ThreadId=227114

fantivero wrote Sep 24, 2010 at 3:11 PM

Other thread where Reactive Extensions is mentioned as an option: http://compositewpf.codeplex.com/Thread/View.aspx?ThreadId=228208

DCherubini wrote Mar 8, 2012 at 6:05 PM

Hi,

For those interested in this subject, you might find useful to know that since since Prism 4.1 release (http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=28950), IDisposable was implemented in the SubscriptionToken class.

To make this implementation possible, an Action<SubscriptionToken> is passed when constructing the SubscriptionToken, which is basically the Unsubcribe method group in the EventBase. Hence, when disposing the SubscriptionToken, this action is executed, thus unsubscribing the event.

Regards,

Damian Cherubini
http://blogs.southworks.net/dcherubini