I've never used dagger/hilt in a multi-module setu...
# dagger
c
I've never used dagger/hilt in a multi-module setup. Lets say I have
app
gradle module which depends on
service
. And
service
inside has
SomeServiceClass
. Would
service
gradle module have a @Module and @Provides, providing the
SomeServiceClass
to
app
gradle module? Or is it more customary for the
service
gradle module to declare what it provides?
a
Hilt enables the decoupled modules to declare what they provide in such scopes and the app module need only to include the gradle module dependencies
c
Interesting. I see the pros and cons of that. Pros, like you said. only the app module has to say that its using service module and things just get provided. Cons, you might add a module to depend on and not realize that it's providing a bunch of things. Right now, my app module has to feed the service module an argument so I wonder how to go about that. For the most part my service module is a network layer, and i want the app module to give the network module the base URL. Hm.
a
Why not just have the service module use it, or have a third module level above provide it?
c
I'm not sure. I guess I'm just used to the app module providing some of those core compile time values, api keys, etc.
I think I have something fairly simple setup, my jvm only module is providing a ServiceClass, and I'm trying to inject it into my app module, but it says that ServiceClass "cannot be provided without an @Provides-annotated method. public abstract static class SingletonC implements App_GeneratedInjector," Am I missing something basic here?
In my network gradle module I have this. Anyone know why this isn't working?
Copy code
@Module
@InstallIn(SingletonComponent::class)
object MyNetworkGradleModule {
  @JvmStatic
  @Provides
  fun provideCustomNameGen() : CustomNameGenServiceInterface {
    return RealCustomNameGen()
  }
}
If I just have
RealCustomNameGen @Inject constructor()
then the injection works. but the second I try to write a module with a provides method, I just get the error message "cannot be provided without an @Provides-annotated method. public abstract static class SingletonC implements App_GeneratedInjector,"" Hrmmm.
Looks like my network module needs kapt possibly
rubber duck
518 Views