How to override binding in GIN
Asked Answered
S

2

6

I find the answer for Guice Overriding Binding in Guice but don't know how to do the same for GIN in GWT.

Thanks in advance!

Sherikasherill answered 6/9, 2011 at 2:17 Comment(2)
Why do you want to override a GinModule for?Waldman
Hi, I'm thinking to replace some binding with mock impl in the unit test. if this is supported, I can replace them by extending the module and override bindings...Sherikasherill
W
5

As far as I know, it's not supported.

To answer your comment:

If you're running "pure" JUnit tests (not GWTTestcases) you don't use GIN, you use Guice, and in Guice you can override modules. If you want to reuse GIN modules, then wrap them using GinModuleAdapter. So you can do something like this:

static class MyGinModule extends GinModule {
  ...
}
static class MyGuiceModule extends AbstractModule {
  ...
}

// And somewhere in your code, here's how you could create the Injector
Module myWrappedGinModule = new GinModuleAdapter(new MyGinModule());
Module myModule = Modules.override(myWrappedGinModule).with(new MyGuiceModule());
Injector injector = Guice.createInjector(myModule);
Waldman answered 6/9, 2011 at 3:42 Comment(1)
+1 for mentioning that in junit tests guice is used instead of gin.Stomy
C
0

Use the @ImplementedBy annotation in your interface.

The class specified in the annotation will be the default implementation.

You can specify another implementation, effectively overriding the default.

For example:

@ImplementedBy(MyWidgetImpl.class)
public interface MyWidget {
  //...
}

public class MyWidgetImpl implements MyWidget {
  //...
}
Chapman answered 15/11, 2011 at 0:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.