I have a large-ish application which's purpose is to aid the user in designing and analysing multiple configurations of Battle Mechs in Mechwarrior: Online. The curious can find the source here.
Essentially the data model is a VFS of directories and files where each file is a "loadout", a loadout is a base Battle Mech "chassis" + all equipment that the user puts on it.
I'm building the application with JavaFX and their take on the MVC pattern.
The UI consists of a main window where the user can manage the VFS and view stats about equipment and available Battle Mechs. From the main window the user can open an existing loadout or create a new one. Each loadout opens in a separate window.
In addition to the loadouts, I have application wide settings and current open VFS, message busses and command stacks (I'm using Command Pattern to provide multilevel-undo/redo throughout the entire application) which are passed around alot. For example the command stack is shared within each window for window-local undo. Each window has a local message bus and there is an application wide message bus too. So most sub-panels needs to get their local command stack and message bus but also the global message bus. I can't really figure out how to get a DI framework to realise which model, command stack and message bus goes where.
Both the main window and loadout windows are quite complex. They display a the full loadout in all it's components, available equipment, real-time stats and graphs. To this end, each window is broken down into sub-panels with their own controller and view, each hooked up to the same model (loadout).
I do manual constructor injection most of my dependencies that make sense. Although it is working fine, I would like to replace a lot of the wiring code with a Dependency Injection framework. And I'm looking at Dagger 2 as it seems light weight and doesn't require me to pull in a bunch of other dependencies.
However I have a hard time seeing how to apply Dagger (or any DI framework) to a data heavy application like mine. I would like to inject a lot of the sub-panels for the windows that I build and their dependencies (which get passed through from the root window as it constructs itself), but the constructor also needs pieces of user data, like the loadout to display or other configured objects which are not services.
I found an article describing the problem I'm facing here To
new or not to
new. Basically my model (which is data driven and loaded from massive XML files) consists entirely of "newables" and is not injectable. But the application controllers would be, if it weren't for the loadout window needing a loadout which is a newable.
The article doesn't discuss any solution to the problem I'm experiencing but at least it highlights it.
This StackOverflow answer basically says to create factories. And I find this boiler plate of creating a factory for each sub-panel kind of off-putting as I thought a DI framework was supposed to reduce the amount of code I need. The other idea was to use more modules but that seems counter to the intention of modules to me, I shouldn't have to create a new module for each model datum. Or the last option to only DI what is known at compile time. But this doesn't help with using a framework.
I'm looking for any ideas on how I should solve my problem: I would like to reduce wiring code in presence of user data. Whether it be better frameworks, patterns or if the best solution is to not use a DI framework then a motivation for that.