I’m using the WPF RibbonMenu which will hold buttons to launch multiple tools. Probably 50 or more. When a tool is selected from the RibbonMenu, it creates a new tab in my AvalonDock layout.
I’m using a ViewModel-First MVVM pattern and the way I have it working at the moment is each tool ViewModel
(I have only added two so far) is injected into the RibbonMenu ViewModel
so it can be added to an ObservableCollection
which is bound to the AvalonDock Manager.
This works great, but it will mean injecting every tool ViewModel
(50+) into the Ribbon Menu ViewModel
which doesn't seem right. I assume each injection will use memory regardless of whether it is used or not by the user?
Similar posts like How to avoid Dependency Injection constructor madness? have answers that say a large number of injections in the constructor means that the class is doing too much and needs to be broken up.
But how is this achieved in my situation where I have a need a single ViewModel
for my RibbonMenu?
EDIT
I'm trying to decide whether to use IoC in the RibbonMenu ViewModel
and have lots of injections (50+), or ignore IoC for this ViewModel only and just create new dependent instances within the ViewModel. For example, each button would trigger a method containing:
HomeViewModel homeViewModel = new HomeViewModel();
Any advice on the best way forward?