-
Notifications
You must be signed in to change notification settings - Fork 4
Feature/hilt to koin #179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Feature/hilt to koin #179
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4f88eb4
CHANGE hilt to koin
Frank1234 2297009
Merge remote-tracking branch 'origin/develop' into feature/hilt-to-koin
Frank1234 35f8d93
Merge remote-tracking branch 'origin/develop' into feature/hilt-to-koin
Frank1234 18dae6c
CHANGE DI improvements
Frank1234 176c0b6
REMOVE ksp
Frank1234 bc572e2
Merge branch 'develop' into feature/hilt-to-koin
Frank1234 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package nl.q42.template.di | ||
|
|
||
| import nl.q42.template.MainApplication | ||
| import nl.q42.template.core.network.di.networkModule | ||
| import nl.q42.template.data.main.di.dataModule | ||
| import nl.q42.template.domain.main.di.domainModule | ||
| import nl.q42.template.home.di.homeModule | ||
| import nl.q42.template.navigation.di.navigationModule | ||
| import nl.q42.template.onboarding.di.onboardingModule | ||
| import nl.q42.template.ui.di.presentationModule | ||
| import org.koin.android.ext.koin.androidContext | ||
| import org.koin.android.ext.koin.androidLogger | ||
| import org.koin.core.context.GlobalContext.startKoin | ||
| import org.koin.dsl.module | ||
|
|
||
|
|
||
| /** | ||
| * Initializes the Koin dependency injection framework, setting up the complete | ||
| * dependency graph for the application. Call on Application start. | ||
| */ | ||
| fun initDependencyInjection(application: MainApplication) { | ||
| startKoin { | ||
| androidLogger() | ||
| androidContext(application) | ||
| modules(appModule) | ||
| } | ||
| } | ||
|
|
||
| val appModule = module { | ||
| includes( | ||
| configModule, | ||
|
|
||
| // features | ||
| homeModule, | ||
| onboardingModule, | ||
|
|
||
| // core | ||
| networkModule, | ||
| navigationModule, | ||
| presentationModule, | ||
|
|
||
| // data | ||
| dataModule, | ||
|
|
||
| // domain | ||
| domainModule | ||
| ) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,48 +1,21 @@ | ||
| package nl.q42.template.di | ||
|
|
||
| import dagger.Module | ||
| import dagger.Provides | ||
| import dagger.hilt.InstallIn | ||
| import dagger.hilt.components.SingletonComponent | ||
| import nl.q42.template.BuildConfig | ||
| import nl.q42.template.core.utils.di.ConfigApiMainPath | ||
| import nl.q42.template.core.utils.di.ConfigAppScheme | ||
| import nl.q42.template.core.utils.di.ConfigAppVersionCode | ||
| import nl.q42.template.core.utils.di.ConfigAppVersionName | ||
| import nl.q42.template.core.utils.di.ConfigLogHttpCalls | ||
| import javax.inject.Singleton | ||
| import nl.q42.template.core.utils.config.ApiMainPath | ||
| import nl.q42.template.core.utils.config.AppScheme | ||
| import nl.q42.template.core.utils.config.AppVersionCode | ||
| import nl.q42.template.core.utils.config.AppVersionName | ||
| import nl.q42.template.core.utils.config.IsLogHttpCalls | ||
| import org.koin.dsl.module | ||
|
|
||
| /** | ||
| * All application wide config can go in here. Used so that other modules don't need to access the BuildConfig, which has drawbacks and can cause bugs: | ||
| * https://blog.dipien.com/stop-generating-the-buildconfig-on-your-android-modules-7d82dd7f20f1 | ||
| */ | ||
| @Module | ||
| @InstallIn(SingletonComponent::class) | ||
| class ConfigModule { | ||
|
|
||
| @Provides | ||
| @Singleton | ||
| @ConfigApiMainPath | ||
| fun providesApiMainPath(): String = BuildConfig.config_api_main_url | ||
|
|
||
| @Provides | ||
| @Singleton | ||
| @ConfigLogHttpCalls | ||
| fun configIsLoggingHttpCalls(): Boolean = BuildConfig.config_log_http_calls | ||
|
|
||
| @Provides | ||
| @Singleton | ||
| @ConfigAppScheme | ||
| fun providesAppScheme(): String = BuildConfig.config_app_scheme | ||
|
|
||
| @Provides | ||
| @Singleton | ||
| @ConfigAppVersionName | ||
| fun providesAppVersionName(): String = BuildConfig.VERSION_NAME | ||
|
|
||
| @Provides | ||
| @Singleton | ||
| @ConfigAppVersionCode | ||
| fun providesAppVersionCode(): Int = BuildConfig.VERSION_CODE | ||
|
|
||
| val configModule = module { | ||
| single { ApiMainPath(BuildConfig.config_api_main_url) } | ||
| single { IsLogHttpCalls(BuildConfig.config_log_http_calls) } | ||
| single { AppScheme(BuildConfig.config_app_scheme) } | ||
| single { AppVersionName(BuildConfig.VERSION_NAME) } | ||
| single { AppVersionCode(BuildConfig.VERSION_CODE) } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
app/src/main/kotlin/nl/q42/template/navigation/OnboardingDestinations.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
app/src/test/kotlin/nl/q42/template/di/KoinCheckModulesTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package nl.q42.template.di | ||
|
|
||
| import androidx.lifecycle.SavedStateHandle | ||
| import kotlinx.coroutines.CoroutineScope | ||
| import org.junit.Test | ||
| import org.koin.core.annotation.KoinExperimentalAPI | ||
| import org.koin.test.KoinTest | ||
| import org.koin.test.verify.verify | ||
|
|
||
| class KoinCheckModulesTest : KoinTest { | ||
|
|
||
| /** | ||
| * Note: this checks that all the dependencies in the DI configuration work well among them, | ||
| * but it doesn't prevent crashes at runtime if the consumer code of the DI dependencies misses | ||
| * a required parameter. This will happen for example with a ViewModel(val myID: String) where | ||
| * the caller of koinViewModel() forgets to pass the myID parameter or the parameter's type doesn't match. | ||
| */ | ||
| @OptIn(KoinExperimentalAPI::class) | ||
| @Test | ||
| fun `Check all Koin modules and their dependencies`() { | ||
Frank1234 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| appModule.verify( | ||
| extraTypes = listOf( | ||
| // Primitive types used in value classes | ||
| String::class, | ||
| Boolean::class, | ||
| Int::class, | ||
| // Android framework types injected at runtime | ||
| SavedStateHandle::class, | ||
| CoroutineScope::class, | ||
| ) | ||
| ) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,3 @@ | ||
| apply { | ||
| plugin(libs.plugins.hilt.get().getPluginId()) | ||
| plugin(libs.plugins.ksp.get().getPluginId()) | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation(libs.hilt) | ||
| ksp(libs.hilt.ksp) | ||
| implementation(libs.koin) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 0 additions & 18 deletions
18
core/navigation/src/main/kotlin/nl/q42/template/navigation/di/ConfigModule.kt
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
core/navigation/src/main/kotlin/nl/q42/template/navigation/di/NavigationModule.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package nl.q42.template.navigation.di | ||
|
|
||
| import nl.q42.template.navigation.viewmodel.MyRouteNavigator | ||
| import nl.q42.template.navigation.viewmodel.RouteNavigator | ||
| import org.koin.core.module.dsl.bind | ||
| import org.koin.core.module.dsl.factoryOf | ||
| import org.koin.dsl.module | ||
|
|
||
| val navigationModule = module { | ||
| factoryOf(::MyRouteNavigator) { bind<RouteNavigator>() } | ||
Frank1234 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.