MessageBox in viewmodels?

Dec 16, 2011 at 7:02 AM

Hello,

reviewing my code I've seen that in some point I've got MessageBox.Show(xxx) but I think it's not properly correct since if I use this models in a unit test, this can cause problem...what's the best approach for dealing with messagebox and send them to a View?

Thanks

Coordinator
Dec 16, 2011 at 8:36 AM

Yeah, MessageBox should not be used in a real application. You should use your own popup. To display a message one often simply publishes a message to the EventAggregator and something like a PopupManager will listen to it and actually display the message. So, when you unit test you won't have the PopupManager and the message will simply be ignored. Messaging through the EventAggregator is the best way to loosly couple different parts of the UI and make them testable independently.