I am getting a stack overflow but I think I have nailed down the problem. The issue is a recursive inject when binding my panel widget. The problem I have ran into is that my PanelWidget takes the Map as a parameter. The problem is then that that this creates an infinite loop.
GinMapProvider
GinMapBinder<String, IDashboardWidget> mapBinder = GinMapBinder
.newMapBinder(binder(), String.class, IDashboardWidget.class);
mapBinder.addBinding(IGaugeWidgetModel.class.getName()).to(MockGaugeWidget.class);
mapBinder.addBinding(IPlotWidgetModel.class.getName()).to(PlotWidget.class);
mapBinder.addBinding(ITableWidgetModel.class.getName()).to(TableWidget.class);
mapBinder.addBinding(IPanelWidgetModel.class.getName()).to(PanelWidget.class);
If I remove Map<String, IDashboardWidget>
the problem goes away of course.
PanelWidget class
@Inject
public PanelWidget(final EventBus eventBus, final Resources resources, Map<String, IDashboardWidget> widgetProvider) {
super(eventBus, resources);
this.widgetProvider = widgetProvider;
initWidget(GWT.<Binder> create(Binder.class).createAndBindUi(this));
widgetsPanel.getElement().getStyle().setPosition(Position.RELATIVE);
this.addDomHandler(widgetSelectedHandler, ClickEvent.getType());
}
I tried this also and inject the WidgetFactory class but this did not solve my problem either. I had hoped creating a singleton would stop it from recreating the bindings.
@Inject
@Provides
@Singleton
WidgetFactory widgetFactory(Map<String, IDashboardWidget> widgetProvider) {
return new WidgetFactory(widgetProvider);
}
BTW I am running this in a GWTTestCase but I don't think this makes a difference.
You probably have circular dependencies, specifically between one of the things you put in the map and the PanelWidget
.
Given the look of your code (WidgetFactory
), I think you might actually need a Map<String, Provider<IDashboardWidget>>
instead of a Map<String, IDashboardWidget>
. And that would cut the circular dependency as a side effect.