lördag 6 november 2010

GWT RequestFactory and GIN

I recently ported my GWT GIN application into 2.1. When diong so I could not hinder my self from testing the new RequestFactory feature. In doing so I followed the guide at google however I did not se any explantion in how to integrate this new feature with GIN. The key is the @Provides annotation in the GIN module.

This is how my solution look.

The RequestFactory

public interface DiveRequestFactory extends RequestFactory {

    @Service(com.smithimage.idive.server.Communication.DiveService.class)
    public interface DiveRequest extends RequestContext {
        Request<DiveProxy> findDive(String id);
        InstanceRequest<DiveProxy, Void> persist();
        InstanceRequest6lt;DiveProxy, Void> remove();
    }

    DiveRequest getDiveRequest();
}


The GIN module

public class DiveServiceModule extends AbstractGinModule{

    @Override
    protected void configure() {
        bind(EventBus.class).to(SimpleEventBus.class).in(Singleton.class);
        bind(MainPresenter.class).in(Singleton.class);
        bind(LogonPresenter.class).in(Singleton.class);
...

        requestStaticInjection();
    }

    @Provides
    @Singleton
    IdiveRequestFactory providesDiveRequestFactory(EventBus eventBus){
        IdiveRequestFactory idiveRequestFactory = GWT.create(IdiveRequestFactory.class);
        idiveRequestFactory.initialize(eventBus);
        return idiveRequestFactory;
    }
}



The consuming class

@Inject
public DiveListPresenter(Display display, MenuDisplay menuDisplay, 
MainPresenter.Display mainDisplay, EventBus eventbus, DiveDAO diveDAO, 
UserDAO userDAO, LocationService locationService,
DiveRequestFactory diveRequestFactory){
...
}

Inga kommentarer:

Skicka en kommentar