Is dependency injection only for service type objects and singleton? (and NOT for gui?)

I am currently experimenting with Google container inversion management. I used to have singlets for almost any service (database, active directory) used by my application. Now I have reorganized the code: all dependencies are set as parameters for the constructors. So far, so good. Now the hardest part is with the graphical user interface. I ran into this problem: I have a table (JTable) of products wrapped in a ProductFrame. I set dependencies as parameters (EditProductDialog).

@Inject
public ProductFrame(EditProductDialog editProductDialog) {
  // ...
}

// ...

@Inject
public EditProductDialog(DBProductController productController, Product product) {
  // ...
}

The problem is that guice cannot know which product I selected in the table, so it cannot know what needs to be entered in EditProductDialog.

( , , ), , EditProductDialog? DBProductController EditProductDialog, ProductFrame, , .

, - dependecy-?

, . , , , ( ) .

+5
5

, , , Product EditProductDialog - , , .

, setProduct(Product) EditProductDialog, :

, , , Guice Assisted Injection, , , .

, Guts-GUI, Swing Guice ( , ). , .

+1

A , , DI. , . .

+1

, , , EditProductDialog.

, Guice ( ). , , , , .

, , (, ProductFrame, ), SetProduct , .

+1

, Guice .

, , .

, singleton , .

SelectionService -

public interface SelectionService {

    Product getSelectedProduct();

    // ...

}

-GUI , , . , GUI, DI GUI .

, .

0

, "GUI".

DI JSP, , . . , , .

, DI .

0
source

All Articles