I need to setup different commands for ViewModels like Close, Edit, Cancel, ShowPic, ShowVideo.
Based on different ViewModels I have, I have common commands like Close, Edit, Cancel that does same operation, only context can be different. Then for other like ShowPic, ShowVideo they are belonging to their own viewmodels.
In such scenarios how to organise your commands as good practice:
- Do you place them all in a separate class call “Commands”?
- Do you place them inside there respective ViewModels even some are common?
- Do you separate common commands from others?
Thanks for your advise and sample how you would organise them.
the answer is “2”.
Even if other ViewModels have the same commands, its your injected services (read up on “IoC” if you don’t know what i’m talking about) that do the heavy lifting in your ViewModels and allow you to avoid redundant logic.