On 27 juin, 19:39, yves <[email protected]> wrote:
> Olivier,
>
> Thanks for the link.
>
> If I try to summarize my problem : Which are the conventions that are
> implicitly used by GIN to bind classes ?
>
> I've already seen gwt-presenter, but it didn't helped me to understand
> how to transform my code to such code :
>
> public class AppModule extends AbstractGinModule {
>
> @Override
> protected void configure() {
>
> bind(EventBus.class).to(DefaultEventBus.class);
>
> bind(MainPresenter.Display.class).to(MainWidget.class);
>
> bind(MenuPresenter.Display.class).to(MenuWidget.class);
>
> bind(IssueEditPresenter.Display.class).to(IssueEditWidget.class);
>
> bind(IssueDisplayPresenter.Display.class).to(IssueDisplayWidget.class);
If you control all of those classes, and they only exist as an
interface+implementation class for testing purpose, then I'd rather
annotate the interfaces with @ImplementedBy, e.g.
@ImplementedBy(MainWidget.class)
public interface Display { ... }
That way, GIN will automatically use MainWidget as if you wrote the
bind().to(); and in case you want to inject some other implementation
(e.g. in some complex tests), you can use bind().to() without risking
a "duplicate binding".
> Is there any doc explaining what is behind the scene with all these
> "bind().to()" calls ?
>
> In my example, if I write something like
>
> bind(SearchPresenter.Display.class).to(someWidget.class);
>
> is it equivalent to
>
> display = d;
> display.getSearchButton().addClickHandler(new
> ClickHandler() {
>
> @Override
> public void onClick(ClickEvent event) {
> doSearch(event);
> }
>
> });
>
> and how to tell GIN that I need to call doSearch() ?
No! GIN is only about dependency injection, i.e. it saves you the
"new", and nothing else.
With the above bind().to() and an @Inject annotation on the
bind(Display) method, then when GIN is asked to instantiate a
SearchPresenter (i.e. when you do not write the "new" yourself) it'll
automatically instantiate a SomeWidget and call bind() with it as an
argument (and when instantiating the SomeWidget, it'll automatically
instantiate the required dependencies and inject them to @Inject-
annotated constructor, fields and methods).
Maybe you should look for Guice tutorials to better understand what
dependency injection is, and how to configure it with Guice.
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.