Thread
#dagger
    Colton Idle

    Colton Idle

    2 years ago
    I have my appComponent that takes in an argument when I call
    .create()
    which is the url that my networkModule needs. java
    public interface AppComponent {
        @Component.Factory
        interface Factory {
            AppComponent create(@BindsInstance @Named("url") String url);
        }
    }
    This is my networkModule. kotlin
    @Module
    class NetworkModule @Inject constructor(@Named("url") val url: String) {...}
    I get this dagger error:
    error: @Component.Factory method is missing parameters for required modules or components: [com.myapp.internal.NetworkModule]
    Ideas? Looks like my BindsInstance should satisfy my networkModule.
    wasyl

    wasyl

    2 years ago
    The documentation suggests that Dagger only instantiates modules that have no-argument constructor, so you would need to pass actual module instance, not the parameters needed to create it
    But if you need to use the url in that module, you can just pass it to provision methods:
    @Provides
    fun foo(@Named("url") url: String) = SomethingThatRequiresUrl(url)
    Colton Idle

    Colton Idle

    2 years ago
    @wasyl thank you. That did the trick. I did not know that you couldn't have @Inject on a modules constructor. I've been providing params to my module since the beginning of time and have just now upgraded dagger 2 to a later version and I wanted to try out the Component.Factory because I heard it's better practice. I don't know exactly why yet, but I have read Jake say that it's better.