R – Where to put Commands when injecting buttons into a ToolBar


In my composite WPF application I am injecting some buttons into the shell's toolbar from a module. These buttons are injected using the region manager in the module's IModule Initialize function.

Since I'm using MVVM and Commands, where would an appropriate place be to put the Command handlers (Execute and CanExecute) for the injected buttons? Right inside the IModule class?

Best Solution

Since this is tagged under MVVM, I assume each "menu button(s)" view you have has a view model. Your view model can contain the handlers for the ICommand (See relay command here). Your view would bind to the ICommands on your view model. I see no reason to hook any events to your IModule. Personally, I never do anything in the IModule::Initialize besides setup dependency injection and initialize my controllers.

Related Question