zalewski.se
06/07/2020, 12:51 PMnetwork <--\ / <-- 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 🤔david.bilik
06/07/2020, 5:33 PMapp
to all modules containing some koin modules and gluing it theredavid.bilik
06/07/2020, 5:35 PMzalewski.se
06/08/2020, 7:43 AMapp
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.david.bilik
06/08/2020, 7:53 AM: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
fun onCreate() {
...
startKoin(
networkingModules +
databaseModules +
...
)
}
david.bilik
06/08/2020, 7:54 AMdavid.bilik
06/08/2020, 7:55 AMzalewski.se
06/08/2020, 7:59 AMapp
implements all the modules from the library (is directly
aware of every module that provides koin modules)? 🤔david.bilik
06/08/2020, 10:19 AMyodgor777
08/21/2020, 7:51 PM