views:

376

answers:

1

I'd like to use gwt-dispatch Command Patter implementation in my app. I'm using also mvp4g. How can I make DefaultDispatchAsync available to inject into my presenters using GIN or make it globally available, so I can access it from my presenters?

+2  A: 

You need to setup a bind for the DefaultDispatchAsync class in your gin module. This will setup the binding for the DispatchAsync interface that the DefaultDispatchAsync class implements. You can then add a DispatchAsync to your presenter constructor and have it injected by gin as required.

I normally then have my presenters contain a private DispatchAsync member, which i assign the injected DispatchAsync argument to inside the constructor. Then the dispatch can be used in the presenter class as required.

So in your GinModule's configure method, add the line

bind(DefaultDispatchAsync.class);

Then on your presenter constructor,

@Inject
public TestPresenter(/*Other injected arguments*/, final DispatchAsync dispatcher) {
   this.dispatcher = dispatcher;
}
Simon.D
I have to setup my injector and ginmodule during application startup, so I assume it will be somewhere in my gwt module entry point?
jjczopek
Yes, you can use GWT create to setup your Ginjector in your Entrypoint class. e.g. private final GwtGinjector injector = GWT.create(GwtGinjector.class);You can then use the instance of the injector created to retrieve your top level presenter and kick off your application.
Simon.D
Thanks a lot - it basically works, but now I need some help with the gwt-dispatch questions, posted here: http://stackoverflow.com/questions/2776726/connecting-gwt-dispatch-with-guice-and-mvp4g
jjczopek