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
140
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
90
Behind the curtains
tiwiz
0
33
The Importance of Being Tested
tiwiz
0
360
An Android Dev start to Kotlin MPP
tiwiz
0
130
Fantastic API and where to find them
tiwiz
0
47
Flipping the Koin @ GDG Dev Party
tiwiz
1
36
Trip into the async world @ NYC Kotlin Meetup
tiwiz
0
76
Trip into the async world
tiwiz
1
96
GraphQL IRL (Android Makers)
tiwiz
0
140
Other Decks in Programming
See All in Programming
法律の脱レガシーに学ぶフロントエンド刷新
oguemon
5
690
[Fin-JAWS 第38回 ~re:Invent 2024 金融re:Cap~]FaultInjectionServiceアップデート@pre:Invent2024
shintaro_fukatsu
0
400
DMMオンラインサロンアプリのSwift化
hayatan
0
300
JavaScriptツール群「UnJS」を5分で一気に駆け巡る!
k1tikurisu
10
1.8k
バックエンドのためのアプリ内課金入門 (サブスク編)
qnighy
8
1.7k
Amazon ECS とマイクロサービスから考えるシステム構成
hiyanger
3
470
ISUCON14公式反省会LT: 社内ISUCONの話
astj
PRO
0
170
Ruby on cygwin 2025-02
fd0
0
130
自動で //nolint を挿入する取り組み / Gopher's Gathering
utgwkk
1
230
『GO』アプリ バックエンドサーバのコスト削減
mot_techtalk
0
110
Alba: Why, How and What's So Interesting
okuramasafumi
0
240
Rails アプリ地図考 Flush Cut
makicamel
1
110
Featured
See All Featured
Writing Fast Ruby
sferik
628
61k
How GitHub (no longer) Works
holman
313
140k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
Six Lessons from altMBA
skipperchong
27
3.6k
Making the Leap to Tech Lead
cromwellryan
133
9.1k
KATA
mclloyd
29
14k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
11
930
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
VelocityConf: Rendering Performance Case Studies
addyosmani
328
24k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Thoughts on Productivity
jonyablonski
69
4.4k
The Cult of Friendly URLs
andyhume
78
6.2k
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!