We evaluate the use of GIN in a GWT project and have had good results with a typical injection through constructor arguments. What we are facing is field-level injection. Fields are always zero. Does anyone have a good example of how to properly achieve the GIN injection rate?
Update:
Here is an example code similar to ours:
public class MVP implements EntryPoint {
public static final HandlerManager EVENT_BUS = new HandlerManager(null);
private final MVPInjector _injector = GWT.create(MVPInjector.class);
public void onModuleLoad() {
RootLayoutPanel.get().add(mainPanel);
ListPresenter listPresenter = _injector.listPresenter();
DetailPresenter detailPresenter = _injector.detailPresenter();
listPresenter.go(listContainer);
detailPresenter.go(detailContainer);
EVENT_BUS.fireEvent(new DataReadyEvent(getData()));
}
}
public class ListPresenter {
private final HandlerManager _eventBus;
private final Map<String, Fruit> _myRecords = new HashMap<String, Fruit>();
private final Display _view;
@Inject
public ListPresenter(Display argView, HandlerManager argEventBus) {
_eventBus = argEventBus;
_view = argView;
}
public void go(HasWidgets argContainer) {
argContainer.clear();
argContainer.add(_view.asWidget());
}
public interface Display {
public Widget asWidget();
public void clear();
public SingleSelectionModel<ViewProxy> getSelectionModel();
public void setData(List<ViewProxy> argData);
}
}
public class DetailPresenter {
private final HandlerManager _eventBus;
private final Display _view;
private Fruit _myRecord;
@Inject
private ImagePresenterFactory _imagePresenterFactory;
@Inject
private TestPresenter _testPresenter;
@Inject
public DetailPresenter(Display argView, HandlerManager argEventBus) {
_view = argView;
_eventBus = argEventBus;
}
public void go(HasWidgets argContainer) {
argContainer.clear();
argContainer.add(_view.asWidget());
if (_testPresenter != null) {
_testPresenter.go();
}
}
public interface Display {
public Widget asWidget();
public HasText getDescriptionControl();
public HasClickHandlers getImageControl();
public HasText getNameControl();
public HasClickHandlers getSaveControl();
public void setEnabledControls(boolean argEnabled);
}
}
public class TestPresenter {
@Inject
HandlerManager _eventBus;
public TestPresenter() {}
public void go() {
if (_eventBus != null) {
_eventBus.toString();
}
else {
}
}
}
@GinModules(MVPModule.class)
public interface MVPInjector extends Ginjector {
DetailPresenter detailPresenter();
ListPresenter listPresenter();
}
public class MVPModule extends AbstractGinModule {
@Provides
@Singleton
public HandlerManager getEventBus() {
return MVP.EVENT_BUS;
}
@Provides
public TestPresenter getTestPresenter() {
return new TestPresenter();
}
@Override
protected void configure() {
bind(ListPresenter.Display.class).to(ListView.class);
bind(DetailPresenter.Display.class).to(DetailView.class);
bind(ImagePresenter.Display.class).to(ImagePopup.class);
install(new GinFactoryModuleBuilder().build(ImagePresenterFactory.class));
}
public interface ImagePresenterFactory {
public ImagePresenter createImagePresenter(ImageResource argImage);
}
}
In the above code, I removed most of the code that is not GIN related. The TestPresenter required by DetailPresenter is successfully implemented, but the HandlerManager, which is required by TestPresenter, is always zero. As you can see, the introduced HandlerManager is not used in the constructor.
source
share