Dependency injection does not work in gwt 2.1

I have a new project in which I use GWT-Views like Composite etc.

I entered the items in the main menu (for example, ProductListbelow) using GinInjector. It works great!

Somewhere I want to have a link from a small component to an item from my main menu in order to update it. I am trying to do it like this:

public class ProductForm extends Composite {
   ...
   @Inject 
   ProductList list;
   ....

}

But when I use list, I always get null. Thus, it ProductListis defined as follows:

public class MyModule extends AbstractGinModule {
   ...
   @Override
   protected void configure() {
      bind(ProductList.class).asEagerSingleton();
      bind(ProductForm.class).asEagerSingleton();
   }
   ...
}

Any idea what I'm doing wrong ?!

Solution : I did not mention that ProductForm is a ProductList element using the UIBinder @UIField tag, so a new object will be created for its injection, not the one created using UIBinder.

, , ( @UIField).

+3
3

: :

"" . , .

Gin - GWT. , class1, ( Guice/Gin), Gin GWT.create . GWT ( i18n):

public interface MyConstants extends Constants {
  String myWords();
}

public class MyWidget {

  @Inject
  public MyWidget(MyConstants myconstants) {
    // The injected constants object will be fully initialized - 
    // GWT.create has been called on it and no further work is necessary.
  }
}

. Gin , GWT.create, Singleton. , .

URL-: http://code.google.com/p/google-gin/wiki/GinTutorial

, .

, , GWT.create(YourFactoryInterface.class).getProductList() .

, GWT.create , :

YourFactoryInterface getFactory() {
  return GWT.create(YourFactoryInterface.class)
}

getFactory().getProductList()
+4

Gin asEagerSingleton() null. , , v1.0. . , , .in(Singleton.class), , Gin 1.5.

+1

Ginjector ProductForm? , , , .

0

Source: https://habr.com/ru/post/1796249/


All Articles