Question

I have a subscribe method in one view model listening for publish events in another view model. For some reason, that I can't figure out, when the publish method is fired, the subscribe method runs multiple times (in my case four each time). I have breakpoints on each publish and other than the first publish call, none of them are firing.

The call stack doesn't change as the subscribe multiple calls happen.

How can I figure out what is causing the multiple calls to subscribe to happen?

UPDATE: Turned out that this was a 'doh' answer when I found it. The viewmodel's in question were a collection of viewmodels for the lines of a table/grid and naturally, the more rows that got added to the grid, the more subscribes were added to the event aggregator. I needed to implement some unsubscribe logic to get rid of the ones I didn't want.

Was it helpful?

Solution

If you're using dependency injection with this, could you create a dummy wrapper class that satisfies IEventAggregator and routes to EventAggregator and catch all the subscribe calls there? I've seen this sort of behavior happen with subscription that happens on ViewModel instantiation combined with tear off tab controls.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top