Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Flipping the Koin
Search
Roberto Orgiu
November 27, 2019
Programming
2
160
Flipping the Koin
Slides of the talk I gave at Kotlin/Everywhere in Stockholm, St. Petersburg and Milan
Roberto Orgiu
November 27, 2019
Tweet
Share
More Decks by Roberto Orgiu
See All by Roberto Orgiu
Wellness & Droid
tiwiz
0
120
Behind the curtains
tiwiz
0
63
The Importance of Being Tested
tiwiz
0
420
An Android Dev start to Kotlin MPP
tiwiz
0
180
Fantastic API and where to find them
tiwiz
0
76
Flipping the Koin @ GDG Dev Party
tiwiz
1
72
Trip into the async world @ NYC Kotlin Meetup
tiwiz
0
120
Trip into the async world
tiwiz
1
140
GraphQL IRL (Android Makers)
tiwiz
0
150
Other Decks in Programming
See All in Programming
AI Agent の開発と運用を支える Durable Execution #AgentsInProd
izumin5210
7
2.3k
AgentCoreとHuman in the Loop
har1101
5
240
AI & Enginnering
codelynx
0
110
20260127_試行錯誤の結晶を1冊に。著者が解説 先輩データサイエンティストからの指南書 / author's_commentary_ds_instructions_guide
nash_efp
1
970
Apache Iceberg V3 and migration to V3
tomtanaka
0
160
Lambda のコードストレージ容量に気をつけましょう
tattwan718
0
130
並行開発のためのコードレビュー
miyukiw
0
180
Rust 製のコードエディタ “Zed” を使ってみた
nearme_tech
PRO
0
180
Automatic Grammar Agreementと Markdown Extended Attributes について
kishikawakatsumi
0
190
AIフル活用時代だからこそ学んでおきたい働き方の心得
shinoyu
0
140
Honoを使ったリモートMCPサーバでAIツールとの連携を加速させる!
tosuri13
1
180
KIKI_MBSD Cybersecurity Challenges 2025
ikema
0
1.3k
Featured
See All Featured
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
0
440
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
120
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
0
140
Build your cross-platform service in a week with App Engine
jlugia
234
18k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
200
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
75
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
61k
sira's awesome portfolio website redesign presentation
elsirapls
0
150
Into the Great Unknown - MozCon
thekraken
40
2.3k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.1k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
120
Ethics towards AI in product and experience design
skipperchong
2
190
Transcript
R O B E R T O O R G
I U - @ _ t i w i z Flippin’ the Koin
Is there a difference? IMPLEMENTATION DI vs SL
DI Container Should only call itself Never called by others
Constructs objects
Service Locator Container Dependency
I’m not really answering this question WHAT IS DAGGER?
@Inject lateinit var myTarget: Target myComponent.inject(this) val myTarget = myComponent.getTarget()
insert-koin.io
Why I like it Kotlin DSL Quick setup Easy to
follow
I’m not really answering this question either WHAT IS KOIN?
private val target: Target by inject() inline fun <reified T
: Any> ComponentCallbacks.inject()
modules declaration val myModule = module { single<Target> { TargetImpl()
} factory { (view: View) -> Presenter(view, get() } viewModel { MyViewModel(get()) } }
Injection private val target: Target by inject { parametersOf(this) }
Injection private val target: Target by inject { parametersOf(this) }
Injection private val target: Target by inject { parametersOf(this) }
Injection val viewModel: MyViewModel by viewModel()
Injection class MyWorker : KoinComponent { override suspend fun doWork():
Result { val target: Target by inject() ... } }
Application startKoin { androidContext(context) androidLogger() modules( listOf(module1,..., moduleN) ) }
Let’s talk about testing “
JUnit + KoinTest
Dependencies koinApplication { androidContext(context) modules(fetchModules()) }.checkModules()
Dependencies koinApplication { androidContext(context) modules(fetchModules()) }.checkModules { create<MyClass> { parametersOf(mock1,...,paramN)
} }
Building a test
startKoin class MyTest : KoinTest { @Before fun setup() {
startKoin { androidContext(context) modules(fetchModules()) } } }
startKoin class MyTest : KoinTest { @Before fun setup() {
startKoin { androidContext(context) modules(fetchModules()) } } }
startKoin stopKoin class MyTest : KoinTest { @After fun tearDown()
{ stopKoin() } }
startKoin stopKoin class MyTest : KoinTest { @After fun tearDown()
{ stopKoin() } }
startKoin stopKoin Test
class MyTest : KoinTest { @Before fun setup() { startKoin
{...} } @Test fun my_test() { } }
class MyTest : KoinTest { @Before fun setup() { startKoin
{...} } @Test fun my_test() { } } private val target: Target by inject() declareMock<Target>() given(target).will { throw Exception() }
Dagger VS Koin
WARNING: Opinionated Ideas ahead
We should use Dagger
Quick setup
Compile time safety Because we all love it.
Scalability
Maintainability
Any questions? “
Use the tools You Like the most
Thanks!