Skip to content

Commit

Permalink
Merge pull request #151 from Team-B1ND/feature/150-login-hilt-koin
Browse files Browse the repository at this point in the history
[Login] Refactor DI Hilt to Koin
  • Loading branch information
8954sood authored Jul 15, 2024
2 parents 5194d3f + e790b5f commit 3c338d0
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 15 deletions.
1 change: 1 addition & 0 deletions data/login/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
alias(libs.plugins.dodam.android)
alias(libs.plugins.dodam.android.kotlin)
alias(libs.plugins.dodam.android.hilt)
alias(libs.plugins.dodam.koin)
}

android {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package com.b1nd.dodam.data.login.di

import com.b1nd.dodam.common.DispatcherType
import com.b1nd.dodam.data.login.repository.LoginRepository
import com.b1nd.dodam.data.login.repositoryimpl.LoginRepositoryImpl
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton
import org.koin.core.qualifier.named
import org.koin.dsl.module

@Module
@InstallIn(SingletonComponent::class)
internal interface RepositoryModule {
@Binds
@Singleton
fun bindsLoginRepository(loginRepositoryImpl: LoginRepositoryImpl): LoginRepository
val loginRepositoryModule = module {
single<LoginRepository> {
LoginRepositoryImpl(get(), get(named(DispatcherType.IO)))
}
}
2 changes: 2 additions & 0 deletions dodam-student/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,6 @@ dependencies {
implementation(projects.network.register)
implementation(projects.data.member)
implementation(projects.network.member)
implementation(projects.data.login)
implementation(projects.network.login)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.b1nd.dodam.bus.di.busRepositoryModule
import com.b1nd.dodam.common.network.di.coroutineScopeModule
import com.b1nd.dodam.common.network.di.dispatchersModule
import com.b1nd.dodam.data.banner.di.bannerRepositoryModule
import com.b1nd.dodam.data.login.di.loginRepositoryModule
import com.b1nd.dodam.data.meal.di.mealRepositoryModule
import com.b1nd.dodam.data.nightstudy.di.nightStudyRepositoryModule
import com.b1nd.dodam.data.outing.di.outingRepositoryModule
Expand All @@ -17,6 +18,7 @@ import com.b1nd.dodam.member.di.memberDataSourceModule
import com.b1nd.dodam.member.di.memberRepositoryModule
import com.b1nd.dodam.network.banner.di.bannerDataSourceModule
import com.b1nd.dodam.network.core.di.networkCoreModule
import com.b1nd.dodam.network.login.di.loginDataSourceModule
import com.b1nd.dodam.network.meal.di.mealDataSourceModule
import com.b1nd.dodam.network.nightstudy.di.nightStudyDataSourceModule
import com.b1nd.dodam.network.outing.di.outingDataSourceModule
Expand Down Expand Up @@ -66,6 +68,8 @@ class DodamApplication : Application() {
registerDataSourceModule,
memberRepositoryModule,
memberDataSourceModule,
loginRepositoryModule,
loginDataSourceModule,
)
}
}
Expand Down
1 change: 1 addition & 0 deletions feature/login/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
alias(libs.plugins.dodam.android.feature)
alias(libs.plugins.dodam.koin)
}

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject

@HiltViewModel
class LoginViewModel @Inject constructor(
private val loginRepository: LoginRepository,
private val datastoreRepository: DatastoreRepository,
) : ViewModel() {
class LoginViewModel @Inject constructor() : ViewModel(), KoinComponent {

private val loginRepository: LoginRepository by inject()
private val datastoreRepository: DatastoreRepository by inject()

private val _uiState = MutableStateFlow(LoginUiState())
val uiState = _uiState.asStateFlow()
Expand Down
1 change: 1 addition & 0 deletions network/login/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
alias(libs.plugins.dodam.android.kotlin)
alias(libs.plugins.dodam.kotlin.serialization)
alias(libs.plugins.dodam.hilt)
alias(libs.plugins.dodam.koin)
}

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton
import org.koin.dsl.module

@Module
@InstallIn(SingletonComponent::class)
Expand All @@ -15,3 +16,10 @@ internal interface DataSourceModule {
@Singleton
fun bindsLoginDataSource(loginService: LoginService): LoginDataSource
}

val loginDataSourceModule = module {

single<LoginDataSource> {
LoginService(get())
}
}

0 comments on commit 3c338d0

Please sign in to comment.