问题
From following the Prism documentation it says there are four ways to communicate across modules -
- Solution commanding
- Region context
- Shared services
Event aggregation
- Can I just chose one of these methods and apply it for all cross-module communcation? Or should I use different methods depending on the situation?
- In particular, in an application Im writing at the moment I have button in one module and when the user clicks it I want to start a thread in another module. Which method of communication would I use for this situation?
回答1:
Ans 1: Yes, you can use a single approach all-over. Most of the times it will be easier to do it that way.
Ans 2: I recommend you use Event Aggregation to do that. That way, you have a very loose coupling between the button click and the thread execution. That way, the listening module just has to be aware of a single event no matter where it was raised from.
Since, it is a single notification and not a bunch of inter-related notifications/communications, it is better to Aggregate an event rather than creating a Shared Service.
来源:https://stackoverflow.com/questions/8625290/communicating-across-modules-with-prism