Skip to content

feat : Dependency Injection Using Koin Library#4

Open
MoonsuKang wants to merge 11 commits into
mainfrom
koin
Open

feat : Dependency Injection Using Koin Library#4
MoonsuKang wants to merge 11 commits into
mainfrom
koin

Conversation

@MoonsuKang

Copy link
Copy Markdown
Owner

✨ 요약

  • closes Dependency Injection Using Koin Library #3

  • Android 환경에 Koin DI(Dependency Injection) 를 적용하였습니다.

  • 기존의 SharedUseCaseProvider 객체를 제거하고, Koin 모듈 기반으로 공통 및 플랫폼 종속 의존성을 구성했습니다.


🔧 구현 상세

🧱 공유 모듈 (shared)

  • sharedAppModule 정의:

val sharedAppModule = module {
    single { UserApi() }
    single<UserRepository> { UserRepositoryImpl(get()) }
    factory { GetUsersUseCase(get()) }
}
  • 기존의 수동 의존성 생성 로직인 SharedUseCaseProvider 제거

  • 공통 비즈니스 로직은 그대로 유지하며, ViewModel이나 UseCase는 DI를 통해 제공


📱 Android 모듈 (androidApp)

  • androidAppModule 정의:

val androidAppModule = module {
    viewModel { UserViewModel(get()) }
}
  • MainActivity에서 startKoin으로 초기화:

startKoin {
    androidContext(this@MainActivity)
    modules(sharedAppModule + androidAppModule)
}
  • viewModel() 키워드를 통해 ViewModel을 주입받을 수 있음


✅ Koin 적용의 장점

  • Factory나 수동 객체 생성 제거 → 코드 간결화

  • 테스트 용이성 증가 (Mock 주입 구조 구성 가능)

  • 명시적인 모듈 정의로 DI 구조 가시성 확보


🍎 iOS 상태 (적용 실패)

❌ 시도한 접근

공통 모듈에서 다음과 같은 함수 정의:

fun initKoinForIos(): Koin = startKoin { ... }.koin

Swift에서 다음처럼 호출을 시도:

let koin = KoinInitializerKt.initKoinForIos()

😥 발생한 문제

시도 결과
KoinInitializerKt 심볼 호출 ❌ Swift에서 인식되지 않음
Obj-C Header 자동 생성 확인 ❌ export 되지 않음

🔍 다음 작업

  • iOS에서의 DI 적용 시도

  • 기능 개발

@MoonsuKang MoonsuKang added the enhancement New feature or request label Apr 6, 2025
@MoonsuKang MoonsuKang requested a review from Copilot April 6, 2025 10:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 9 out of 11 changed files in this pull request and generated no comments.

Files not reviewed (2)
  • androidApp/build.gradle.kts: Language not supported
  • shared/build.gradle.kts: Language not supported
Comments suppressed due to low confidence (1)

androidApp/src/main/java/com/river/kmp/android/MainActivity.kt:20

  • Ensure that 'androidAppModule' is imported (e.g., import com.river.kmp.android.androidAppModule) to avoid unresolved reference errors during build.
modules(sharedAppModule + androidAppModule)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dependency Injection Using Koin Library

2 participants