2

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)?

stephanos
  • 3,319
  • 7
  • 33
  • 47
  • possible duplicate of [Use Dagger modules without the "injects" directive](http://stackoverflow.com/questions/20477417/use-dagger-modules-without-the-injects-directive) – Gimby Oct 28 '14 at 14:08
  • not related to this issue, but Wicket 1.4 is end-of-life. You really should be using Wicket 6.x – Martijn Dashorst Nov 28 '14 at 13:28

0 Answers0