fix(DI): properly add modules to koin
This commit is contained in:
parent
1b5cc48fdf
commit
c73edaa12f
3 changed files with 20 additions and 22 deletions
|
|
@ -20,39 +20,40 @@ class ManagerApplication : Application() {
|
||||||
androidContext(this@ManagerApplication)
|
androidContext(this@ManagerApplication)
|
||||||
|
|
||||||
// HTTP
|
// HTTP
|
||||||
module {
|
modules(module {
|
||||||
singleOf(::provideJson)
|
single { provideJson() }
|
||||||
singleOf(::provideHttpClient)
|
single { provideHttpClient() }
|
||||||
}
|
})
|
||||||
|
|
||||||
// Services
|
// Services
|
||||||
module {
|
modules(module {
|
||||||
|
singleOf(::HttpService)
|
||||||
singleOf(::GithubService)
|
singleOf(::GithubService)
|
||||||
singleOf(::MavenService)
|
singleOf(::MavenService)
|
||||||
singleOf(::AliucordGithubService)
|
singleOf(::AliucordGithubService)
|
||||||
}
|
})
|
||||||
|
|
||||||
// Repositories
|
// Repositories
|
||||||
module {
|
modules(module {
|
||||||
singleOf(::GithubRepository)
|
singleOf(::GithubRepository)
|
||||||
singleOf(::AliucordMavenRepository)
|
singleOf(::AliucordMavenRepository)
|
||||||
}
|
})
|
||||||
|
|
||||||
// ViewModels
|
// ViewModels
|
||||||
module {
|
modules(module {
|
||||||
viewModelOf(::HomeViewModel)
|
viewModelOf(::HomeViewModel)
|
||||||
viewModelOf(::PluginsViewModel)
|
viewModelOf(::PluginsViewModel)
|
||||||
viewModelOf(::AboutViewModel)
|
viewModelOf(::AboutViewModel)
|
||||||
viewModelOf(::InstallViewModel)
|
viewModelOf(::InstallViewModel)
|
||||||
viewModelOf(::SettingsViewModel)
|
viewModelOf(::SettingsViewModel)
|
||||||
viewModelOf(::UpdaterViewModel)
|
viewModelOf(::UpdaterViewModel)
|
||||||
}
|
})
|
||||||
|
|
||||||
// Managers
|
// Managers
|
||||||
module {
|
modules(module {
|
||||||
singleOf(::providePreferences)
|
single { providePreferences() }
|
||||||
singleOf(::provideDownloadManager)
|
single { provideDownloadManager() }
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,13 +10,12 @@ import org.koin.core.scope.Scope
|
||||||
import java.net.Inet4Address
|
import java.net.Inet4Address
|
||||||
import java.net.InetAddress
|
import java.net.InetAddress
|
||||||
|
|
||||||
context(Scope)
|
@Suppress("UnusedReceiverParameter")
|
||||||
fun provideJson() = Json {
|
fun Scope.provideJson() = Json {
|
||||||
ignoreUnknownKeys = true
|
ignoreUnknownKeys = true
|
||||||
}
|
}
|
||||||
|
|
||||||
context(Scope)
|
fun Scope.provideHttpClient() = HttpClient(OkHttp) {
|
||||||
fun provideHttpClient() = HttpClient(OkHttp) {
|
|
||||||
val json: Json = get()
|
val json: Json = get()
|
||||||
|
|
||||||
engine {
|
engine {
|
||||||
|
|
|
||||||
|
|
@ -6,14 +6,12 @@ import com.aliucord.manager.domain.manager.DownloadManager
|
||||||
import com.aliucord.manager.domain.manager.PreferencesManager
|
import com.aliucord.manager.domain.manager.PreferencesManager
|
||||||
import org.koin.core.scope.Scope
|
import org.koin.core.scope.Scope
|
||||||
|
|
||||||
context(Scope)
|
fun Scope.providePreferences(): PreferencesManager {
|
||||||
fun providePreferences(): PreferencesManager {
|
|
||||||
val ctx: Context = get()
|
val ctx: Context = get()
|
||||||
return PreferencesManager(ctx.getSharedPreferences("preferences", Context.MODE_PRIVATE))
|
return PreferencesManager(ctx.getSharedPreferences("preferences", Context.MODE_PRIVATE))
|
||||||
}
|
}
|
||||||
|
|
||||||
context(Scope)
|
fun Scope.provideDownloadManager(): DownloadManager {
|
||||||
fun provideDownloadManager(): DownloadManager {
|
|
||||||
val application: Application = get()
|
val application: Application = get()
|
||||||
return DownloadManager(application)
|
return DownloadManager(application)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue