Owen Kirkeby
fun main() { startKoin { modules(applicationModule) } ScopeTestClass().start(TestClass1()) } class ScopeTestClass : KoinComponent { fun start(test: TestInterface) { val test2 = get<TestInterface2>(test.getScopeName()) println(test2) } } interface TestInterface class TestClass1(val data: String = "hello") : TestInterface class TestClass2(val data: String = "hi") : TestInterface interface TestInterface2 { fun print() } class Test1MatchRunner(val payload: String = "fdsafd") : TestInterface2 { override fun print() { println(payload) } } class Test2MatchRunner(val number: Int = 7) : TestInterface2 { override fun print() { println(number) } } val applicationModule = module { scope<TestClass1> { scoped<TestInterface2> { Test1MatchRunner("hello") } } scope<TestClass2> { scoped<TestInterface2> { Test2MatchRunner(9) } } }
A modern programming language that makes developers happier.