dagger icon indicating copy to clipboard operation
dagger copied to clipboard

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

Open CoatedMoose opened this issue 10 years ago • 9 comments

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.

CoatedMoose avatar Jan 12 '15 22:01 CoatedMoose

Someone else with the same issue.

http://stackoverflow.com/questions/25100115/google-auto-factory-dagger-integration-dependencies-on-injected-code

CoatedMoose avatar Jan 12 '15 22:01 CoatedMoose

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.

gk5885 avatar Jan 12 '15 22:01 gk5885

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

CoatedMoose avatar Jan 12 '15 23:01 CoatedMoose

In that case, we need @cgruber to do a sync with the google repo.

gk5885 avatar Jan 13 '15 04:01 gk5885

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);
    }

digitalbuddha avatar Oct 13 '15 03:10 digitalbuddha

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.

JakeWharton avatar Oct 13 '15 03:10 JakeWharton

@gk5885 mentions that Dagger 2 has resolved the issue, I thought it might be worth noting that extending BasicAnnotationProcessor does not fix this.

digitalbuddha avatar Oct 13 '15 03:10 digitalbuddha

@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.

jag4364u avatar Oct 07 '16 06:10 jag4364u

As was mentioned, Dagger 2.x is on the http://github.com/google/dagger project. The square project is for Dagger 1.x

cgruber avatar Oct 12 '16 22:10 cgruber