Hi! I’m trying to figure out best way to deal with...
# koin
z
Hi! I’m trying to figure out best way to deal with Koin in multi module project… Is there any recommended way? So for example:
Copy code
network  <--\              / <-- home   <--\
             | repository |                 | app
database <--/              \ <-- login  <--/
In such scenario (app depends on home&login where home&login depends on repository where repository depends on network… etc, depends on mean using
implementation
, not
api
), how to manage Koin modules? I was thinking of having network provide it’s own modules and passing it up to repository, repository would consume it, add it’s own and pass it up further.. This will cause the problem where many network and repository koin modules would be provided to the app module (I know I can fix it by allowing overriding the modules) . It’s also not so flexible for testing, I can’t provide testNetwork module in home or login feature as these modules are unaware of the network. Another thing is that I can’t really test database as it’s needs to be aware of Android context (sqldelight..) so to test checkModules configuartion I would need to mock it there. Different idea I had was to create another module like
di
that would be aware of all the modules that expose some Koin modules. In
di
I would connect everything together and expose it for the app module (which would depend on
di
). But this doesn’t really solves the problem with testing 🤔
d
our approach is to have dependency from
app
to all modules containing some koin modules and gluing it there
i don’t understand really the problem with tests, we don’t have any koin in tests
z
@david.bilik Hmm so if I understand you correctly, you are passing koin modules from the
app
to some other modules and how you are gluing it there? About the testing, so first of all I would like to test Koin configuration for every module. Another thing is that during some Unit test I just wanna get the instance from the Koin and test it’s functionalities, don’t worry about it’s dependencies. So generally, startKoin with some modules at the beginning of the tests, get instance from there, test it, close koin.
d
each of my gradle modules provides koin modules - eg.
:libraries:networking
has public
val networkingModules : List<Module>
, then
libraries:database
would have
val databaseModules : List<Module>
as well .. and then in
Application.onCreate
i do something like
Copy code
fun onCreate() {
   ... 
   startKoin(
      networkingModules + 
      databaseModules + 
      ...
   )
}
with this approach you can’t test each modules DI graph independently though
I’ve tried to comeup with some solution where each module would contain it’s own DI graph but i don’t think that Koin is suited for that
z
I see, so it’s passing the koin modules like bottom -> up. In your case
app
implements all the modules from the library (is
directly
aware of every module that provides koin modules)? 🤔
d
yes
y
David can I test all of my koin modules