dagger
dagger copied to clipboard
Broken binding when providing an auto-factory generated implementation without a fully qualified class name.
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.
Someone else with the same issue.
http://stackoverflow.com/questions/25100115/google-auto-factory-dagger-integration-dependencies-on-injected-code
There have been major changes in Dagger 2 to address these types of issues. Presumably, if someone were to migrate the Dagger 1 processors to extend BasicAnnotationProcessor
this would get resolved.
I do not know which BasicAnnotationProcessor
you are referring to. A search for filenames hasn't yielded any results (checked square/dagger and google/dagger).
In that case, we need @cgruber to do a sync with the google repo.
Came here from SO question, I'm using Dagger 2 with AutoFactory and seeing same behavior, only works with fully qualified names.
@Provides
ABManager provideABManagerImpl(com.example.android.ab.ABManagerImplFactory factory ) {
return factory.create(3, IMMEDIATELY);
}
This is not the repository for Dagger 2. You want https://github.com/google/dagger
On Mon, Oct 12, 2015 at 11:28 PM Mike Nakhimovich [email protected] wrote:
Came here from SO question, I'm using Dagger 2 with AutoFactory and seeing same behavior, only works with fully qualified names.
@Provides ABManager provideABManagerImpl(com.nytimes.android.ab.ABManagerImplFactory factory ) { return factory.create(3, IMMEDIATELY); }
— Reply to this email directly or view it on GitHub https://github.com/square/dagger/issues/456#issuecomment-147584754.
@gk5885 mentions that Dagger 2 has resolved the issue, I thought it might be worth noting that extending BasicAnnotationProcessor does not fix this.
@digitalbuddha as you mentioned factory classes works with fully qualified names ! for me still it is not working. do you any other suggestion on this to make it work? i am using dagger<2.5> . please help.
As was mentioned, Dagger 2.x is on the http://github.com/google/dagger project. The square project is for Dagger 1.x