background preloader

Gin

Facebook Twitter

GWT Sushi. Named annotaion is not working - google-gin. Guice with GWT. Java - GWT - GIN - GWTP - Dispatcher Injection Problem. GWT.runAsync with GIN — amateur in motion (r579) GWT-2.0 has great new feature called Code Splitting what allows to split module in smaller compiled parts and request parts only when (if) they’re needed.

GWT.runAsync with GIN — amateur in motion (r579)

But I’m using GIN to wire all internal application object graph (models, presenters, views, service classes) and of corse if it’s left as is (one Ginjector) no code is split. So I came up with this simple “design pattern” to continue using GIN modules while taking advantage of code splitting: Split monolithic GIN module in multiple modules For each GIN/runAsync module create Loader interface and implementation with void load(LoaderCallback cb) method Loader: on first load creates GIN module possibly injects module stylesheets stores GIN injector instance in private static field connects parent and new GIN modules together calls LoaderCallback method Example In this example (live version is deployed on AppEngine) I have one “base” StoriesModule: and AdminModule: Pretty basic stuff.

But AdminModule needs EventBus instance from StoriesModule. » GWT Dependency Injection recipes using GIN. Dependency Injection is already a well-known and discussed topic in the Java world and there are a good number of well established frameworks and libraries supporting this concept.

» GWT Dependency Injection recipes using GIN

While for many developers it is a must, some others seem not to be so convinced and think that it does not bring that much value to a project. Of course, it depends on the project, but with the time, it seems that its benefits have been widely accepted and support for it has been incorporated in almost every piece of software where it seemed to make sense. This is also the case of Google Web Toolkit where GIN provides dependency injection support on the client side. GIN is a mainly a GWT-based version of the Google’s homegrown dependency injection framework GUICE. But because the GWT applications run on top of the browser JavaScript engine instead of on the JVM, some of the GUICE features are not available in GIN. The source code of the application can be downloaded here.

GinTutorial - google-gin - Using GIN to create a GWT widget - GIN (GWT INjection) is Guice for Google Web Toolkit client-side code. This tutorial will show how a simple GWT widget can be constructed with GIN.

GinTutorial - google-gin - Using GIN to create a GWT widget - GIN (GWT INjection) is Guice for Google Web Toolkit client-side code

You should be already familiar with Guice - if not, then please read the Guice User Guide for an introductory overview of Guice concepts. In regular Guice, you would use: Deferred Binding/GIN in GWT widgets/libraries. » GWT Dependency Injection recipes using GIN (III) This is the third part of a series about Dependency Injection in Google Web Toolkit using GIN.

» GWT Dependency Injection recipes using GIN (III)

If you have not yet read the first and second parts, you maybe should do it before reading this third and last article. In this article, we will introduce two GIN features: “constants binding” and “static injection”. To do this with an example, let’s refactor the “serve button” in the “Simulator” main class of the second part into an own class: ... final Button button = new Button("Serve! "); button.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { button.setVisible(false); injector.getRacket().serve(); } }); ... Here the new extracted “ServeView” class: public class ServeView extends Button { @Inject public ServeView(final Racket racket, @Named("ServeText") String serveText) { super(serveText); addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { setVisible(false); racket.serve(); } }); } } And our “InjectorModule” like this: Conclusions. » GWT Dependency Injection recipes using GIN (II) This is the second part of a series about Dependency Injection in Google Web Toolkit using GIN.

» GWT Dependency Injection recipes using GIN (II)

If you have not yet read the first part, there we explained how to integrate GIN in an existing GWT sample application. In this second part, we will continue enhancing the sample application while explaining other types of injection supported by GIN. Encapsulating the event bus In the first part of this series, we configured the GWT event bus used in the original application to be injected in some of the application elements.

Using an event bus is a “best practice” that helps communicating the different components in the application while keeping a low coupling between them. @Singleton public class Racket { private final EventBus fEventBus; private GwtEvent<? As you can see at the code, our class is annotated with “@Singleton” to indicate the injection scope and “@Inject” to get the event bus injected in the constructor.