Assume one of the ViewModel receive some command that is pretty general to application (and can be also executed from other ViewModels, for example “stop ftp server”). What should i do?
- propogate
OnPropertyChangedevent to container, execute command in some top-level view (MainWindowViewModel) - pass some “singleton service layer” class to each
ViewModel, execute static method directly in theViewModel, likeUtils.StopFtpServer() - other?
Static commands are used by Microsoft. Therefore, it can’t be a bad idea to use a static class which defines all these global commands.
To give an example about what I’ve said:
This is a static class that offers global command used for text edition.
That said, I’ll advice to avoid to put business logic into commands. Encapsulate it into Business objects and call these objects from the command. That way you’ll decouple the Gui and the Business and have a more testable application.