Colton Idle

06/10/2020, 12:14 AM
I have my appComponent that takes in an argument when I call
which is the url that my networkModule needs. java
Copy code
public interface AppComponent {
    interface Factory {
        AppComponent create(@BindsInstance @Named("url") String url);
This is my networkModule. kotlin
Copy code
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.


06/10/2020, 7:12 AM
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:
Copy code
fun foo(@Named("url") url: String) = SomethingThatRequiresUrl(url)

Colton Idle

06/11/2020, 4:22 AM
@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.