Leviathan
Service locator implementation of DI pattern
Add the dependency below to your module's build.gradle.kts file:
| Module | Version |
|---|
| leviathan |  |
Multiplatform
sourceSets {
commonMain.dependencies {
implementation("io.github.composegears:leviathan:$version")
implementation("io.github.composegears:leviathan-compose:$version")
}
}
Android / jvm
Use same dependencies in the dependencies { ... } section
Base usage
Create Module (recommend to use object) and implement Leviathan marker interface.
Create fields using these functions:
Example
Declare your dependencies
class SampleRepository()
class SampleRepositoryWithParam(val param: Int)
class SampleRepositoryWithDependency(val dependency: SampleRepository)
interface SampleInterfaceRepo
class SampleInterfaceRepoImpl : SampleInterfaceRepo
Create module
Dependencies usage:
Migration to 4.0.0
Before:
object Module : Leviathan() {
val repo by instanceOf { SampleRepository() }
val config by mutableOf { 1 }
}
After:
class ModuleWithDsl : Leviathan {
val repo by instanceOf { SampleRepository() }
val config by mutableOf { 1 }
}
object Module {
val repo by Leviathan.instanceOf { SampleRepository() }
val config by Leviathan.mutableOf { 1 }
}
Contributors
Thank you for your help! ❤️
License
Developed by ComposeGears 2024
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this except compliance the License.
You may obtain a copy of the License at
http:
Unless applicable law agreed to writing, software
distributed under the License distributed an BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express implied.
See the License the specific language governing permissions
limitations under the License.