We are trying to integrate our web framework Wicket (1.4.x) with the dependency injection of Dagger. To do this we created a Wicket component injector:
class DaggerComponentInjector
extends ConfigurableInjector
implements IComponentInstantiationListener {
...
@Override
public Object inject(Object object, IFieldValueFactory factory) {
if (!AppModule.canInject(object.getClass())) {
return object;
}
final DaggerGraphHolder holder = Application.get().getMetaData(DaggerGraphHolder.GRAPH_KEY);
holder.getGraph().inject(object);
return object;
}
@Override
public void onInstantiation(Component component) {
inject(component);
}
...
It checks if the object's class contains an @Inject anywhere and then calls Dagger to inject the dependencies.
Unfortunately, this doesn't work:
public class LogoutPage extends WebPage {
@Inject
private AuthenticationService authenticationService;
...
}
In our logout page a service is injected. But when we navigate to the page this happens:
Caused by: java.lang.IllegalArgumentException: No inject registered for members/com.myapp.LogoutPage. You must explicitly add it to the 'injects' option in one of your modules.
at dagger.ObjectGraph$DaggerObjectGraph.getInjectableTypeBinding(ObjectGraph.java:309)
at dagger.ObjectGraph$DaggerObjectGraph.inject(ObjectGraph.java:290)
We have hundreds of classes like this.
How do we solve this issue WITHOUT manually adding all classes to the @Module inject array (or creating a provider method)?