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
120
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
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 @ GDG Dev Party
tiwiz
1
33
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
From Spring Boot 2 to Spring Boot 3 with Java 21 and Jakarta EE
ivargrimstad
0
200
DMMプラットフォームがTiDB Cloudを採用した背景
pospome
9
4.1k
PHPはいつから死んでいるかの調査
chiroruxx
1
400
スクラムガイドのスプリントレトロスペクティブを改めて読みかえしてみた / Re-reading the Sprint Retrospective Section in the Scrum Guide
mackey0225
3
450
Rubyでたのしむクリエイティブコーディング/Enjoy Creative coding with Ruby
chobishiba
1
200
Goのmultiple errorsについて (2024年4月版)
syumai
4
990
Hanami and htmx
bkuhlmann
0
210
Elm 0.19.0 Changes
bkuhlmann
0
490
Fast JSX: Don't clone props object #28768
yossydev
1
130
StoreKit2によるiOSのアプリ内課金のリニューアル
kangnux
0
110
VSCodeでのDatabricks開発もお勧めしたい/I would also recommend Databricks development with VSCode.
kazumain
0
260
Micro Frontends for Java Microservices - Devnexus 2024
mraible
PRO
0
500
Featured
See All Featured
What’s in a name? Adding method to the madness
productmarketing
PRO
16
2.6k
Mobile First: as difficult as doing things right
swwweet
216
8.6k
Ruby is Unlike a Banana
tanoku
96
10k
Reflections from 52 weeks, 52 projects
jeffersonlam
345
19k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
241
1.2M
Atom: Resistance is Futile
akmur
259
25k
Building Better People: How to give real-time feedback that sticks.
wjessup
355
18k
Designing with Data
zakiwarfel
96
4.8k
Learning to Love Humans: Emotional Interface Design
aarron
267
39k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
2
1.3k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
79
43k
KATA
mclloyd
15
12k
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!