I have a GWT app which uses Gin/Guice.
My need : call a method after that all fields are injected.
Here is an extract of Javadoc about @Inject
Constructors are injected first, followed by fields, and then methods.
So my idea was to have only one method annotated with @Inject
and use it as a post-injection method. Here is an extract of my code :
//An injected attribute (a JSR 303 validator)
@Inject
private Validator validator;
//A constructor with some injectable args.
@Inject
public MyClass(...){
}
//And my post-injection method
@Inject
private void postInjection(){
Log.warn("Validator null? "+(validator==null));
}
Problem : The log shows true
( = validator is null, as if it had not been injected yet). Later, the validator is called on a button click and appears to be non-null. I tested with other injectable attributes and have the same problem.
1) Is there a common pattern to have a post injection method with Gin?
2) Is the injection order different with Gin in GWT? Is this a bug?
There was a bug in GIN up to 2.0, it's been fixed in 2.1.
https://code.google.com/p/google-gin/issues/detail?id=183