Skip to content

Commit

Permalink
Migrate to com.ivy-apps.di
Browse files Browse the repository at this point in the history
  • Loading branch information
ILIYANGERMANOV committed Aug 23, 2024
1 parent f6491ef commit 29ad7d0
Show file tree
Hide file tree
Showing 14 changed files with 17 additions and 278 deletions.
3 changes: 1 addition & 2 deletions composeApp/src/commonMain/kotlin/data/di/DataModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import data.LessonRepository
import data.TopicsRepository
import ivy.di.Di
import ivy.di.Di.register
import ivy.di.DiModule

object DataModule : DiModule {
object DataModule : Di.Module {
override fun init() = Di.appScope {
register { TopicsRepository(Di.get(), Di.get()) }
register { CourseRepository(Di.get(), Di.get()) }
Expand Down
3 changes: 1 addition & 2 deletions composeApp/src/commonMain/kotlin/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ package di
import ivy.di.Di
import ivy.di.Di.register
import ivy.di.Di.singleton
import ivy.di.DiModule
import systemNavigation
import ui.navigation.Navigation
import util.DispatchersProvider
import util.DispatchersProviderImpl

object AppModule : DiModule {
object AppModule : Di.Module {

override fun init() {
Di.appScope {
Expand Down
7 changes: 4 additions & 3 deletions composeApp/src/commonMain/kotlin/ui/navigation/Screen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ui.navigation

import androidx.compose.runtime.Composable
import ivy.di.Di
import ivy.di.FeatureScope
import kotlinx.coroutines.CompletableJob
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand All @@ -14,17 +15,17 @@ abstract class Screen {
private lateinit var job: CompletableJob
protected lateinit var screenScope: CoroutineScope

protected abstract fun onDi(): Di.ScreenScope.() -> Unit
protected abstract fun onDi(): Di.Scope.() -> Unit

fun initialize() {
job = SupervisorJob()
screenScope = CoroutineScope(Dispatchers.Main + job)
onDi().invoke(Di.ScreenScope)
onDi().invoke(FeatureScope)
}

fun destroy() {
job.cancel()
Di.clearInstances(Di.ScreenScope)
Di.clearInstances(FeatureScope)
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CourseScreen(
) : Screen() {
override val path: String = "course"

override fun onDi(): Di.ScreenScope.() -> Unit = {
override fun onDi(): Di.Scope.() -> Unit = {
register { CourseViewStateMapper() }
register {
CourseViewModel(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import ui.screen.home.mapper.HomeViewStateMapper
class HomeScreen : Screen() {
override val path: String = "home"

override fun onDi(): Di.ScreenScope.() -> Unit = {
override fun onDi(): Di.Scope.() -> Unit = {
register { HomeViewStateMapper() }
register { HomeViewModel(Di.get(), Di.get(), Di.get()) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import ui.screen.intro.composable.IntroContent
class IntroScreen : Screen() {
override val path: String = "intro"

override fun onDi(): Di.ScreenScope.() -> Unit = {
override fun onDi(): Di.Scope.() -> Unit = {
register { IntroViewModel(Di.get()) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class LessonScreen(
) : Screen() {
override val path: String = "lesson"

override fun onDi(): Di.ScreenScope.() -> Unit = {
override fun onDi(): Di.Scope.() -> Unit = {
register { LessonTreeManager() }
register { LessonViewStateMapper(Di.get(), Di.get()) }
register { OnBackClickEventHandler(Di.get()) }
Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ kotlin-coroutines = "1.8.0"
jebrains-exposed = "0.49.0"

[libraries]
ivyApps-di = { module = "com.ivy-apps:di", version = "0.0.3" }
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activityCompose" }
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "androidx-appcompat" }
androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "androidx-constraintlayout" }
Expand Down
3 changes: 1 addition & 2 deletions server/src/main/kotlin/ivy/learn/data/di/DataModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ package ivy.learn.data.di

import ivy.di.Di
import ivy.di.Di.register
import ivy.di.DiModule
import ivy.learn.data.database.Database
import ivy.learn.data.repository.CoursesRepository
import ivy.learn.data.repository.LessonsRepository
import ivy.learn.data.repository.TopicsRepository
import ivy.learn.data.source.LessonContentDataSource

object DataModule : DiModule {
object DataModule : Di.Module {
override fun init() = Di.appScope {
register { Database() }
register { LessonContentDataSource(Di.get(), Di.get()) }
Expand Down
3 changes: 1 addition & 2 deletions server/src/main/kotlin/ivy/learn/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ package ivy.learn.di
import ivy.di.Di
import ivy.di.Di.register
import ivy.di.Di.singleton
import ivy.di.DiModule
import ivy.learn.Environment
import ivy.learn.EnvironmentImpl
import ivy.learn.LearnServer
import ivy.learn.ServerConfigurationProvider

class AppModule(private val devMode: Boolean) : DiModule {
class AppModule(private val devMode: Boolean) : Di.Module {
override fun init() = Di.appScope {
register<Environment> { EnvironmentImpl() }
register { ServerConfigurationProvider(Di.get()) }
Expand Down
1 change: 1 addition & 0 deletions shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ kotlin {

commonMain.dependencies {
implementation(libs.bundles.arrow)
api(libs.ivyApps.di)
}
}
}
99 changes: 0 additions & 99 deletions shared/src/commonMain/kotlin/ivy/di/DiContainer.kt

This file was deleted.

6 changes: 3 additions & 3 deletions shared/src/commonMain/kotlin/ivy/di/SharedModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import kotlinx.serialization.modules.subclass
import platform
import io.ktor.client.plugins.logging.LogLevel as KtorLogLevel

object SharedModule : DiModule {
object SharedModule : Di.Module {

override fun init() = Di.appScope {
singleton<Platform> { platform() }
Expand All @@ -37,7 +37,7 @@ object SharedModule : DiModule {
}

@OptIn(ExperimentalSerializationApi::class)
private fun Di.DiScope.json() = singleton {
private fun Di.Scope.json() = singleton {
Json {
ignoreUnknownKeys = true
isLenient = true
Expand All @@ -59,7 +59,7 @@ object SharedModule : DiModule {
}
}

private fun Di.DiScope.ktorClient() = singleton {
private fun Di.Scope.ktorClient() = singleton {
val platform = Di.get<Platform>()
platform.httpClient {
install(ContentNegotiation) {
Expand Down
Loading

0 comments on commit 29ad7d0

Please sign in to comment.