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 @ GDG Dev Party
Search
Roberto Orgiu
May 02, 2020
Programming
1
33
Flipping the Koin @ GDG Dev Party
Slides of my talk at GDG Dev Party Italy 2020
Roberto Orgiu
May 02, 2020
Tweet
Share
More Decks by Roberto Orgiu
See All by Roberto Orgiu
Wellness & Droid
tiwiz
0
75
Behind the curtains
tiwiz
0
24
The Importance of Being Tested
tiwiz
0
280
An Android Dev start to Kotlin MPP
tiwiz
0
100
Fantastic API and where to find them
tiwiz
0
34
Flipping the Koin
tiwiz
2
120
Trip into the async world @ NYC Kotlin Meetup
tiwiz
0
61
Trip into the async world
tiwiz
1
84
GraphQL IRL (Android Makers)
tiwiz
0
120
Other Decks in Programming
See All in Programming
PostmanでAPIの動作確認が楽になった話
h455h1
0
170
DMMプラットフォームがTiDB Cloudを採用した背景
pospome
9
4.1k
使ってみよう Azure AI Document Intelligence
kosmosebi
2
330
大規模Reactアプリのリアーキテクチャ~8万行のTanStack Query移行の軌跡~
kj455
4
970
見た目から始める生産性向上
ikumatadokoro
8
960
禅の心を手に入れよ
eltociear
1
160
Fragment Composition of GraphQL
quramy
7
1k
CDKコントリビュートの最初の壁を越えよう! -簡単issueの見つけ方-
badmintoncryer
2
110
Apache Hive 4 on Treasure Data
ryukobayashi
0
350
Scalable Customer Journey Orchestration (CJO)
lewuathe
0
350
What We Can Learn From OSS
inouehi
0
420
"config" ってなんだ? / What is "config"?
okashoi
0
240
Featured
See All Featured
Documentation Writing (for coders)
carmenintech
60
3.9k
Raft: Consensus for Rubyists
vanstee
132
6.3k
Building an army of robots
kneath
300
41k
Stop Working from a Prison Cell
hatefulcrawdad
266
19k
GraphQLの誤解/rethinking-graphql
sonatard
50
9.2k
Thoughts on Productivity
jonyablonski
58
3.8k
Large-scale JavaScript Application Architecture
addyosmani
504
110k
Imperfection Machines: The Place of Print at Facebook
scottboms
260
12k
Reflections from 52 weeks, 52 projects
jeffersonlam
345
19k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
18
6.9k
The Power of CSS Pseudo Elements
geoffreycrofte
60
5k
Bash Introduction
62gerente
604
210k
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
androiddevs.it
Use the tools You Like the most
Thanks!