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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
71
Trip into the async world @ NYC Kotlin Meetup
tiwiz
0
110
Trip into the async world
tiwiz
1
140
GraphQL IRL (Android Makers)
tiwiz
0
150
Other Decks in Programming
See All in Programming
0→1 フロントエンド開発 Tips🚀 #レバテックMeetup
bengo4com
0
540
なぜSQLはAIぽく見えるのか/why does SQL look AI like
florets1
0
430
Architectural Extensions
denyspoltorak
0
260
今こそ知るべき耐量子計算機暗号(PQC)入門 / PQC: What You Need to Know Now
mackey0225
3
360
今から始めるClaude Code超入門
448jp
7
8k
Grafana:建立系統全知視角的捷徑
blueswen
0
320
【卒業研究】会話ログ分析によるユーザーごとの関心に応じた話題提案手法
momok47
0
190
AgentCoreとHuman in the Loop
har1101
5
210
Smart Handoff/Pickup ガイド - Claude Code セッション管理
yukiigarashi
0
110
LLM Observabilityによる 対話型音声AIアプリケーションの安定運用
gekko0114
2
410
Package Management Learnings from Homebrew
mikemcquaid
0
170
ThorVG Viewer In VS Code
nors
0
760
Featured
See All Featured
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.3k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.8k
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
Designing for Timeless Needs
cassininazir
0
120
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.7k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
0
190
The Power of CSS Pseudo Elements
geoffreycrofte
80
6.1k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.8k
Music & Morning Musume
bryan
47
7.1k
Ruling the World: When Life Gets Gamed
codingconduct
0
130
Leading Effective Engineering Teams in the AI Era
addyosmani
9
1.5k
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!