Note that there are some explanatory texts on larger screens.

plurals
  1. POIs dependency injection only for service type objects and singletons? (and NOT for gui?)
    text
    copied!<p>I'm currently experimenting with the Google's guice inversion of control container. I previously had singletons for just about any service (database, active directory) my application used. Now I refactored the code: all the dependencies are given as parameters to constructors. So far, so good. Now the hardest part is with the graphical user interface. I face this problem: I have a table (JTable) of products wrapped in an ProductFrame. I give the dependencies as parameters (EditProductDialog).</p> <pre><code>@Inject public ProductFrame(EditProductDialog editProductDialog) { // ... } // ... @Inject public EditProductDialog(DBProductController productController, Product product) { // ... } </code></pre> <p>The problem is that guice can't know what Product I have selected in the table, so it can't know what to inject in the EditProductDialog.</p> <p>Dependency Injection is pretty viral (if I modify one class to use dependency injection I also need to modify all the other classes it interacts with) so my question is should I directly instantiate EditProductDialog? But then I would have to pass manually the DBProductController to the EditProductDialog and I will also need to pass it to the ProductFrame and all this boils down to not using dependency injection at all.</p> <p>Or is my design flawed and because of that I can't really adapt the project to dependecy injection?</p> <p>Give me some examples of how you used dependency injection with the graphical user interface. All the examples found on the Internet are really simple examples where you use some services (mostly databases) with dependency injection.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload