开发者

How to determine who is calling the prism eventaggregator subscribe? or multiple subscribe calls

开发者 https://www.devze.com 2023-04-03 17:31 出处:网络
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 m

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, non开发者_如何转开发e 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号