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
// A model class | |
class HelloModel(val who: String = "Koin") | |
// Service interface | |
interface HelloService { | |
fun hello(): String | |
} | |
// Service implementation with injected helloModel instance | |
class HelloServiceImpl(val helloModel: HelloModel) : HelloService { |
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 HelloController(val service: HelloService) { | |
init { | |
get("/hello") { | |
service.sayHello() | |
} | |
} | |
} |
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
// A simple Spark controller | |
class HelloController { | |
init { | |
get("/hello") { | |
"Hello !" | |
} | |
} | |
} |
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
public class MyApplication extends Application { | |
@Override | |
public void onCreate() { | |
super.onCreate(); | |
// Call helper to start Koin | |
JavaAppKoinKt.start(this); | |
} | |
} |
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 DetailPresenter(val view : DetailContract.View) : DetailContract.Presenter { | |
override fun getDetail(id: String) { | |
// Get detail and notify it to view ... | |
} | |
} |
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 DetailActivity : AppCompatActivity(), DetailContract.View { | |
val presenter: DetailContract.Presenter by inject(parameters = | |
mapOf("DETAIL_ACTIVITY" to this)) | |
} |
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 myModule = applicationContext { | |
context("A"){ | |
context("B"){ | |
} | |
} | |
context("C"){ | |
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
// Listen with ContextCallback | |
registerContextCallBack(object : ContextCallback{ | |
// Notified on context dropped | |
override fun onContextReleased(contextName: String) { | |
println("Context $contextName has been dropped") | |
} | |
}) |
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 DetailActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
//... | |
val detailViewModel = getViewModel<DetailViewModel>(parameters = mapOf("id" to id)) | |
detailViewModel.getDetail() | |
} | |
} |
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(){ | |
val myModel by viewModel<MyViewModel>() | |
} |
OlderNewer