Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWT.create(Class<?>) vs. GIN?

It looks like GWT has its own baked-in DI mechanism (GWT.create(Class<?>)). What benefits does GIN offer on top of this? Should you ever use them in conjunction with one another, or are they mutually exclusive? I like Guice so I'm tempted to use GIN, but don't want to introduce it if GWT already does the same stuff right out of the box.

like image 651
Bantha Fodder Avatar asked Oct 23 '12 12:10

Bantha Fodder


1 Answers

Gin and GWT.create have a few differences - Gin is more about providing dependencies via the @Inject annotation, either on fields, setters, or the constructor, whereas GWT.create is specifically about obtaining an implementation. Gin will use any constructor you provide, but you must specifically provide the replacement type, whereas GWT.create will only work with a default constructor, and your 'rebind rules' don't need to be quite as precise, and can even cause new classes to be created at compile time. It also is able to look at what environment the user is running and select a specific set of rules based on that, which Gin is not able to do.

Gin actually makes use of GWT.create to get these other features - if you don't have a rule defined, Gin will call GWT.create automatically. This means if you have a rule like

@Inject MyRemoteServiceAsync rpcService;

Gin will call GWT.create to build that rpc call. This also works for UiBinder, Editor Drivers, I18n Messages and Constants, etc.

If you already understand and like Guice, Gin shouldn't be a big step for you, and you'll still have the ability to directly invoke GWT.create, or implicitly ask Gin to do it. In fact, in order to even use Gin, you need to call GWT.create(MyGinjector.class) to get the ball rolling.

like image 91
Colin Alworth Avatar answered Sep 21 '22 21:09

Colin Alworth