#456·dagger

Broken binding when providing an auto-factory generated implementation without a fully qualified class name.

Author: CoatedMooseCreated Jan 12, 2015Updated Oct 12, 2016

I am pretty sure this is a dagger issue and not an google/auto one, but feel free to correct me.

When trying to provide an implementation of an interface:

import com.example.ExampleClassImplFactory;
@Module(...)
public class ExampleModule {
    @Provides
    ExampleClassFactory provideExampleClass(ExampleClassImplFactory impl) {
        return impl;
    }
}

Where the implementation is the result of an AutoFactory, I get this exception (at runtime - issues at compile time):

Caused by: java.lang.IllegalStateException: Could not load class ExampleClassImplFactory needed for binding ExampleClassImplFactory
    at dagger.internal.FailoverLoader.getAtInjectBinding(FailoverLoader.java:68)
    at dagger.internal.Linker.createBinding(Linker.java:225)
    at dagger.internal.Linker.linkRequested(Linker.java:142)
    at dagger.ObjectGraph$DaggerObjectGraph.getInjectableTypeBinding(ObjectGraph.java:336)
    at dagger.ObjectGraph$DaggerObjectGraph.inject(ObjectGraph.java:306)
...

The following works:

@Module(...)
public class ExampleModule {
    @Provides
    ExampleClassFactory provideExampleClass(com.example.ExampleClassImplFactory impl) {
        return impl;
    }
}

I assume the issue is that auto factory hasn't generated the class yet when dagger processes the @Provides method and maybe adding an implied reference the the fully qualified package name would help.