IEventAggregator: instances not unsubscribed?

Aug 10, 2012 at 11:11 AM

In WP7 I'm registering a VM via  "container.PerRequest<VM>" and in the ctor of VM i'm calling events.Subscribe(this).

It seems that old instances of VM  in the handler list of IEventAggregator don't get removed:

This causes the unwanted behaviour that  a published event is  sent to the SAME VM-Instance as often as the VM has been constructed, which is just as often as the View has been navigated to...

So when a VM is registered via "PerRequest", the Framework should automatically remove the VM instance from the EventAggregators handler list  when navigating away from a Page (?)

Or what could be a solution to this (without using PerInstance or Singelton) ?




Aug 15, 2012 at 8:35 AM

There is no auto (un-)subscription in the EventAggregator.

As you are subscribing the viewmodel, you are also responsible for unsubscribing (e.g. in override of Screen.CanClose).