Issue 199 in google-gin: GIN does not respect injection order when subclassing

27 views
Skip to first unread message

googl...@googlecode.com

unread,
Sep 24, 2014, 10:21:35 AM9/24/14
to googl...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 199 by david.nouls: GIN does not respect injection order when
subclassing
https://code.google.com/p/google-gin/issues/detail?id=199

What steps will reproduce the problem?
According to the Guice injection points document at:
https://github.com/google/guice/wiki/InjectionPoints

injection methods of super classes are called before the methods of a
subclass.

Here is some small unit test for Guice that shows that the correct order is
first ThingA.inject() and then ThingB.anotherInject().

If you use GIN, ThingB.anotherInject() is invoked before ThingA.inject()

public class InjectInheritance {

static class ThingA {
boolean initialized;

@Inject
public void inject() {
this.initialized = true;
System.out.println("ThingA:inject called");
}
}

static class ThingB extends ThingA {
private boolean testOK = false;

@Inject
public void anotherInject() {
testOK = this.initialized;
System.out.println("ThingB:anotherInject called");
}

public boolean isSuccess() {
return testOK;
}
}

@Test
public void guiceMethodInjectionInheritance() {
Module module = new AbstractModule() {
@Override
protected void configure() {
}
};
Injector guice = Guice.createInjector(module);
ThingB b = guice.getInstance(ThingB.class);
assertTrue(b.isSuccess());
}

// This part of the code needs to be executed by GIN.
public void ginInheritance() {
App app = GWT.create( App.class);
ThingB b = app.createB();
assertTrue(b.isSuccess());
}

@GinModules(MyGinModule.class)
static interface App extends Ginjector {
public ThingB createB();
}

static class MyGinModule extends AbstractGinModule {
@Override
protected void configure() {
}
}

What is the expected output? What do you see instead?
I expect this order of invocation
ThingA.inject();
ThingB.anotherInject();

However I get this in Gin:
ThingB.anotherInject();
ThingA.inject();


What version of the product are you using? On what operating system?
GWT 2.6.1 / GIN 2.1.2

Please provide any additional information below.



--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

googl...@googlecode.com

unread,
Jan 30, 2015, 4:37:12 AM1/30/15
to googl...@googlegroups.com

Comment #1 on issue 199 by david.nouls: GIN does not respect injection
I tried with GIN 2.1.2 and GWT 2.7.0 and the problem still exists.
I wrote a simple unittest that exposes the problem.
It looks like the name of the method influences the orde in which the
methods are injected.
So if my base class has something like injectZ and the derived class has
injectA then injectA is done before injectZ. Which can cause issues if you
method injection depends on the base class to be fully injected.
I attached my example unittest to show the problem.

Attachments:
gin_inheritance.zip 2.4 KB
Reply all
Reply to author
Forward
0 new messages