Search code examples
gwtguicegwt-gin

GIN - Pass a constructor parameter to my ClientModule


I have a pretty simple GIN usage in my GWT project. I followed the Guice tutorial to set it up.

I want to bind an unchanging Long variable to an annotation in my AbstractGinModule subclass. The problem is that I do now know the value of the variable until runtime (onModuleLoad). I have the value before I create the Ginjector... I just don't know how to get it into my Client module.

I've seen answers that say I can pass a constructor parameter to my ClientModule... but I don't see where it gets constructed. It's just annotation wiring.

@GinModules(MyClientModule.class)
public interface MyGinjector extends Ginjector {
}

public class MyClientModule extends AbstractGinModule {

    @Override
    protected void configure() {
        bindConstant().annotatedWith(named("MyConstant")).to(???);
    }

public class MyEntryPoint implements EntryPoint {

    @Override
    public void onModuleLoad() {

        long myValue = 123456L; 
        MyGinjector injector = GWT.create(MyGinjector.class);
}

So how can I get my value 123456L into the configure() method of MyClientModule?


Solution

  • The only way to pass values to GIN is to use shared state, i.e. some static variable/method that you can set on one side and access/call from your GinModule.