Your recommendation however, is to try as much as possible to rely on only one injector, that instantiate the different modules as required.
To make my question simple, do you carry around your injector within the code, or you keep the injection in one place ?
I find myself in many situation where i feel like i need to let the creation happens at different position in my code. I don't know if it is normal to have assisted injection everywhere.
I never used providers. But i think we are in the same situation.
Let me take one example.
I have a Service A that needs a Service B. However, B needs a parameter, that requires some computation in A first to happens. I always end up creating an assisted factory with one parameter only? Is that the right thing to do here ?
This leads to another question that i have in mind: Is it ok to have a parameterized module? In the sense that, you have a constructor of your module that takes parameters. Why i'm asking this, well i have the following situation.
I'm using JavaFX2. I want to encapsulate/modularized the creation of my interface. In javaFx2 everything happens in the Application.start method which provide you with the primaryStage.
override def start(primaryStage: Stage): Unit = {
//Create your interface here
//initialized whatever else you may think of here (could launch a thread as well)
primaryStage.show()
}
I have an interfaceBuilder class that takes the primary stage as parameter. At least for now. I see two solution here when using guice. Either an assisted inject, or a module that is parameterized.
Also, when my interfaceBuilder has build the interface, i can get from it the different Component that it has created. For example, BuildInterface(): AppInterface. where AppInterface, contain the relevant component that i need: TreeView, StartButton, TextArea, etc.. AppInterface is in a sense a data Structure.
Now the interesting part here is that, out of those component i need to create, Services that handle them. TreeViewService ( which in my application, participantViewService) They independently encapsulate the logic to manage the logic related their component. TreeViewService takes the TreeViewComponent has parameter in its constructor. In the more complex version especially for the StartService and the shutDown Service they take a controler or whatever class that encapsulate the management of the application as parameter.
This is the simplified version. but as you can see. At every step of the way, i need some parameter to be provided for the creation of my service. InterFacebuilder Service needs the primary stage, The other view Service needs the the view component created by the InterfaceBuilder and another component (e.g. Controler) provided by the Application creation Logic.
How would you deal with that in this case? Assisted Injection, Parameterized Modules ?
PS: I'm not using the SceneBuilder of JavaFX2