Prism Event Aggregation - subscriber not triggered

前端 未结 2 1277
萌比男神i
萌比男神i 2021-02-07 07:20

I\'m working on implementing an event aggregation with Prism. I have a few modules, and I want each of them to subscribe to events that tells them when they are requested. I sta

2条回答
  •  鱼传尺愫
    2021-02-07 07:31

    The Prism Event Aggregator uses Weak References to link to the events. This is to prevent memory leaks from event handlers.

    Once a module initializer has been run it's disposed of, so your event handler is being destroyed before the event is being fired. You can tell Prism to keep the event handler around by using an overload of Subscribe.

    evnt.Subscribe(MyModuleRequested, true);
    

    As a pattern, I tend to put any event subscribers in a separate class, and call that class from the modules Initialize method. That way the events stay alive but separate while the module is still destroyed.

提交回复
热议问题