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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With