On 20 oct, 23:59, atoy40 <
anthony.hinsin...@gmail.com> wrote:
> > And you can go further by having AppActivityMapper being @Inject'ed
> > Provider<>s for the activities (and you'll annotate their constructor
> > with @Inject) instead of new'ing them, and add some bindings and
> > providers for the PlaceHistoryXxx thing too (moving almost all the
> > HelloMVP code into the GIN module)
>
> Hi,
>
> i'm also looking to integrate GIN with gwt2.1 and espacially the MVP
> part. Into the Google MVP example code, the ActivityMapper is defined
> as (note the comment) :
>
> public Activity getActivity(Place place)
> {
> // This is begging for GIN
> if (place instanceof HelloPlace)
> return new HelloActivity((HelloPlace) place, clientFactory);
> else if (place instanceof GoodbyePlace)
> return new GoodbyeActivity((GoodbyePlace) place, clientFactory);
>
> }
>
> My questions are :
>
> - what is begging ? the "new" ? or the chain of "if+instanceof" (i
> don't know how you can omit/replace it using GIN) ?
As Peter said, I don't think you can replace the "if" cascade with GIN
(though you can do it with a GWT code generator, I've already done it:
http://gwt-code-reviews.appspot.com/845802/diff/46002/38011 ), so it's
probably the "new" thing.
> - how, if you use a set of Provider<PlaceType>, can you transmit the
> place instance (which can contains important information for the
> activity) to the activity ?
The idea (IMO) would be to use AssistedInject (or you own hand-crafted
factories if you don't want/can't use GIN 1.1-SNAPSHOT / Guice 2.1-
SNAPSHOT) with Provider<ActivityType>:
public Activity getActivity(Place place) {
if (place instanceof HelloPlace)
return helloActivityProvider.get(((HelloPlace) place);
else if (place instanceof GoodbyePlace)
return goodbyeActivityProvider.get((GoodbyePlace) place);
}
Note how the dependency on clientFactory (which mean: any dependency)
is moved to the provider/factory, which GIN can inject (and you use
AssistedInject, there's even less to code).