Access ginjector

29 views
Skip to first unread message

Tushar Bhasme

unread,
Feb 24, 2015, 11:26:10 AM2/24/15
to gwt-pl...@googlegroups.com
Is there a way to access the ginjector created by gwtp? I need to create a standalone widget but it needs access to EventBus and DispatchAsync implementations which I wanted to get through the ginjector. Since I want it to be standalone, I do not want to inject anything. I actually want to create this class using Builder pattern and I want it to resolve the core dependency by itself.

Thanks,
Tushar

Nicolas Morel

unread,
Feb 24, 2015, 1:19:56 PM2/24/15
to gwt-pl...@googlegroups.com
A working solution but a bit ugly : you create a "factory" class and declare it as eagerSingleton in your gin module.

public final MyFactory {

 
private static Provider<EventBus> eventBusProvider;

 
MyFactory(){}

 
public static EventBus getEventBus(){
   
return
eventBusProvider.get();
 
}

 
@Inject
 
void setEventBus(Provider<EventBus>
eventBusProvider) {
   
MyFactory.
eventBusProvider = eventBusProvider;
 
}
 
}


Maxime Mériouma-Caron

unread,
Feb 24, 2015, 2:49:13 PM2/24/15
to gwt-pl...@googlegroups.com
You might also want to consider using requestStaticInjection(YourWidget.class) inside your Gin module

tushar bhasme

unread,
Feb 24, 2015, 3:56:50 PM2/24/15
to gwt-pl...@googlegroups.com
Seems static injection would give me same result as the Factory suggested by Nicolas, just in a little cleaner way.
So to inject at instance level, I would have to inject a static Provider?


Thanks,
Tushar Bhasme

--
You received this message because you are subscribed to a topic in the Google Groups "GWTP" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gwt-platform/WFuL5CD1oQQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gwt-platform...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Maxime Mériouma-Caron

unread,
Feb 24, 2015, 4:05:01 PM2/24/15
to gwt-pl...@googlegroups.com
The EventBus is bound as a singleton, so I'm not sure there's a benefit in injecting a provider instead of injecting the EventBus itself
Reply all
Reply to author
Forward
0 new messages