Tuesday, May 1, 2012

Injecting dependencies with GIN/Guice

I typically have this kind of code pattern in my GWT project:

Menu errorMenu = new Menu(user, userController, -1);
Menu searchMenu = new Menu(user, userController, 0);

errorView.setMenu(errorMenu);
searchView.setMenu(searchMenu);
How do I inject a Menu instance in the ErrorView and other "views" using
Gin/Guice:

public ErrorView implements View {
// Inject menu instance here
private Menu menu;
}
Such that, I don't have to manually create and set objects?

Also for the Menu class, how can I inject the "user" and
"userController" objects so I don't have to pass it on each Menu
instance every time it is instantiated.


--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment