https://kotlinlang.org logo
#dagger
Title
# dagger
a

Archie

08/07/2020, 8:54 AM
Hi Guys, may I ask a question. I am using
Hilt
for Android DI. I am wondering whats the recommended approach of where to define the
Hilt
Modules. In a multi-module project, is it ok to define
Hilt
modules in each module? So for example I have a
UserModule (Android Submodule)
and with in it I define the
Hilt
Module. Or is it better to define all
Hilt
Modules inside the
app
Module itself?
r

Rafal

08/07/2020, 5:53 PM
If you declare your hilt module inside another gradle module you might need to declare your module as
api
instead of
implementation
so you won't end up with non-existent class errors
Also this will mean that you need to run your annotation processor for each module using hilt
We ended up with having our dagger setup in 2 modules (app and one layer below, called ui)
👍 1
d

David

08/07/2020, 7:39 PM
Put your dagger modules closest to the code to which it pertains. Whether hilt permits this I don't know. dagger-android infamously became quite difficult in multimodule (just at the same time it was all the rage)
I use the component dependency method to wire these things up. c.f. the
dependencies
block. In the old days of Dagger 2.0 this made dagger scoping outside of subcomponents difficult. However in later Dagger component dependencies with varying lifecycles is permitted i'm told. Yet to try it out...moved to TyoeScript & React Native for my sins..😂
For reference here is my app structure using @jw's script from a while back; https://twitter.com/BrantApps/status/1154925368949837824?s=19
(cheers for the script if your reading this)
🍻 1
2 Views