This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// generated sources | |
import org.koin.ksp.generated.* | |
fun main(){ | |
startKoin { | |
modules(CoffeeAppModule().module) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Module | |
@ComponentScan("org.koin.sample.coffee") | |
class CoffeeAppModule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Single | |
class ElectricHeater : Heater | |
@Single | |
class Thermosiphon(private val heater: Heater) : Pump | |
@Single | |
class CoffeeMaker(private val pump: Pump, private val heater: Heater) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val dataModule = module { | |
// data components definitions | |
} | |
val featureModule1 = module { | |
includes(dataModule) | |
// feature1 definitions | |
} | |
val featureModule2 = module { | |
includes(dataModule) | |
// feature2 definitions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ClassA(val b : ClassB) | |
class ClassB() | |
module { | |
singleOf(::ClassA) | |
singleOf(::ClassB) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyAdapter(val presenter : MyPresenter) | |
module { | |
scope<MyActivity> { | |
// get MyPresenter instance from current scope | |
scoped { MyAdapter(get()) } | |
scoped { MyPresenter() } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyActivity : AppCompatActivity, AndroidScopeComponent { | |
// use Activity Retained Scope | |
override val scope : Scope by activityRetainedScope() | |
val presenter : MyPresenter by inject() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module { | |
viewModel { MyViewModel() } | |
} | |
class MyActivity : AppCompatActivity() { | |
val myViewModel : MyViewModel by viewModel() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyActivity : AppCompatActivity, AndroidScopeComponent { | |
// get current Activity's scope | |
override val scope : Scope by activityScope() | |
// MyPresenter is resolved from MyActivity's scope | |
val presenter : MyPresenter by inject() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module { | |
// Declare a scope for MyActivity | |
scope<MyActivity> { | |
scoped { MyPresenter() } | |
} | |
} | |
class MyActivity : ScopeActivity() { | |
val presenter : MyPresenter by inject() | |
} |
NewerOlder