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
Rafal
08/07/2020, 5:54 PM
Also this will mean that you need to run your annotation processor for each module using hilt
Rafal
08/07/2020, 5:55 PM
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)
David
08/07/2020, 7:43 PM
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..😂