SlideShare a Scribd company logo
1 of 65
Download to read offline
Koin Quickstart
Matt Clarke - Auckland Android Community - Dec
2018
What is Koin?
What is Koin?
• From insert-koin.io:
What is Koin?
• From insert-koin.io:
• A pragmatic lightweight dependency injection
framework for Kotlin developers.
What is Koin?
• From insert-koin.io:
• A pragmatic lightweight dependency injection
framework for Kotlin developers.
• Written in pure Kotlin, using functional resolution only:
no proxy, no code generation, no reflection.
What is Koin?
• From insert-koin.io:
• A pragmatic lightweight dependency injection
framework for Kotlin developers.
• Written in pure Kotlin, using functional resolution only:
no proxy, no code generation, no reflection.
• Koin is a DSL, a light container and a pragmatic API
What is Koin?
What is Koin?
public class Person {
private String name;
private int age = 0;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Person person = (Person) o;
if (name != null ? !name.equals(person.name) : person.name != null) return false;
if (age != 0 ? age != person.age : person.age != 0) return false;
}
@Override
public int hashCode() {
int result = name != null ? name.hashCode() : 0;
result = 31 * result + age;
return result;
}
@Override
public String toString() {
return "Person{" +
"name='" + name + ''' +
", age='" + age + ''' +
'}';
}
}
What is Koin?
data class Person(var name: String, var age: Int)
What is Koin?
data class Person(var name: String, var age: Int)
i.e. “Koin is to Dagger as Kotlin is to Java”
Live (mob) coding
Deep(er) dive: How does
any of this work?
Deep(er) dive: How does
any of this work?
val postModule = module {
single { PostPresenter(get()) }
}
Deep(er) dive: How does
any of this work?
val postModule = module {
single { PostPresenter(get()) }
}
How does any of this work?
How does any of this work?
/**
* Create a Module
* Gather definitions
* @param path : Path of the module
* @param createOnStart : module definitions will be tagged as `createOnStart`
* @param override : allow all definitions from module to override definitions
*/
fun module(
path: String = Path.ROOT,
createOnStart: Boolean = false,
override: Boolean = false,
definition: ModuleDefinition.() -> Unit
): Module =
{ koinContext -> ModuleDefinition(path, createOnStart, override,
koinContext).apply(definition) }
org/koin/dsl/module/Module.kt
How does any of this work?
/**
* Create a Module
* Gather definitions
* @param path : Path of the module
* @param createOnStart : module definitions will be tagged as `createOnStart`
* @param override : allow all definitions from module to override definitions
*/
fun module(
path: String = Path.ROOT,
createOnStart: Boolean = false,
override: Boolean = false,
definition: ModuleDefinition.() -> Unit
): Module =
{ koinContext -> ModuleDefinition(path, createOnStart, override,
koinContext).apply(definition) }
org/koin/dsl/module/Module.kt
How does any of this work?
/**
* Create a Module
* Gather definitions
* @param path : Path of the module
* @param createOnStart : module definitions will be tagged as `createOnStart`
* @param override : allow all definitions from module to override definitions
*/
fun module(
path: String = Path.ROOT,
createOnStart: Boolean = false,
override: Boolean = false,
definition: ModuleDefinition.() -> Unit
): Module =
{ koinContext -> ModuleDefinition(path, createOnStart, override,
koinContext).apply(definition) }
org/koin/dsl/module/Module.kt
How does any of this work?
How does any of this work?
kotlinlang.org/docs/reference/lambdas.html
How does any of this work?
How does any of this work?
val postModule = module {
single { PostPresenter(get()) }
}
How does any of this work?
val postModule: Module = module(definition = {
single { PostPresenter(get()) }
})
How does any of this work?
val postModule: Module = module(definition = {
single { PostPresenter(get()) }
})
How does any of this work?
How does any of this work?
/**
* Create a Module
* Gather definitions
* @param path : Path of the module
* @param createOnStart : module definitions will be tagged as `createOnStart`
* @param override : allow all definitions from module to override definitions
*/
fun module(
path: String = Path.ROOT,
createOnStart: Boolean = false,
override: Boolean = false,
definition: ModuleDefinition.() -> Unit
): Module =
{ koinContext -> ModuleDefinition(path, createOnStart, override,
koinContext).apply(definition) }
org/koin/dsl/module/Module.kt
How does any of this work?
/**
* Create a Module
* Gather definitions
* @param path : Path of the module
* @param createOnStart : module definitions will be tagged as `createOnStart`
* @param override : allow all definitions from module to override definitions
*/
fun module(
path: String = Path.ROOT,
createOnStart: Boolean = false,
override: Boolean = false,
definition: ModuleDefinition.() -> Unit
): Module =
{ koinContext -> ModuleDefinition(path, createOnStart, override,
koinContext).apply(definition) }
org/koin/dsl/module/Module.kt
How does any of this work?
val postModule: Module = module(definition = {
single { PostPresenter(get()) }
})
How does any of this work?
val postModule: Module = module(definition = {
this.single { PostPresenter(get()) }
})
How does any of this work?
val postModule: Module = module(definition = {
this.single { PostPresenter(get()) }
})
How does any of this work?
How does any of this work?
/**
* Provide a single instance definition
* (unique instance)
*
* @param name
* @param createOnStart - need to be created at start
* @param override - allow definition override
* @param definition
*/
inline fun <reified T : Any> single(
name: String = "",
createOnStart: Boolean = false,
override: Boolean = false,
noinline definition: Definition<T>
): BeanDefinition<T> {
return provide(name, createOnStart, override, Kind.Single, definition)
}
org/koin/dsl/context/ModuleDefinition.kt
Type-Safe Builders
Type-Safe Builders
https://kotlinlang.org/docs/reference/type-safe-builders.html
Type-Safe Builders
Type-Safe Builders
What about this?
What about this?
/**
* Activity displaying the list of posts
*/
class PostActivity : AppCompatActivity(), PostView {
private val presenter: PostPresenter by inject()
// ...
What about this?
/**
* Activity displaying the list of posts
*/
class PostActivity : AppCompatActivity(), PostView {
private val presenter: PostPresenter by inject()
// ...
No magic
No magic
• Koin takes full advantage of Kotlin’s adv. language
features
No magic
• Koin takes full advantage of Kotlin’s adv. language
features
• E.g. reified generics, lambdas with receivers, type
inference
No magic
• Koin takes full advantage of Kotlin’s adv. language
features
• E.g. reified generics, lambdas with receivers, type
inference
• Less opaque/magical than annotation processing pipeline
for application developers
Testability?
Testability?
// Just tag your class with KoinTest to unlock your testing power
class SimpleTest : KoinTest {
// lazy inject BusinessService into property
val service : BusinessService by inject()
@Test
fun myTest() {
// You can start your Koin configuration
startKoin(myModules)
// or directly get any instance
val service : BusinessService = get()
// Don't forget to close it at the end
closeKoin()
}
}
What about Scopes?
What about Scopes?
val appModule = module {
// single instance of HelloRepository
single<HelloRepository> { HelloRepositoryImpl() }
// Scoped MyScopePresenter instance
scope("session") { MyScopePresenter(get())}
}
What about Scopes?
What about Scopes?
class MyScopeActivity : AppCompatActivity() {
// inject MyScopePresenter from "session" scope
val scopePresenter: MyScopePresenter by inject()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_simple)
// bind "session" scope to component lifecycle
bindScope(getOrCreateScope("session"))
//...
}
}
Koin vs. Dagger overview
Koin vs. Dagger overview
• Koin pros:
Koin vs. Dagger overview
• Koin pros:
• Less boilerplate. Less arcane, easy to learn
Koin vs. Dagger overview
• Koin pros:
• Less boilerplate. Less arcane, easy to learn
• No annotation processing/code gen. Just language features
Koin vs. Dagger overview
• Koin pros:
• Less boilerplate. Less arcane, easy to learn
• No annotation processing/code gen. Just language features
• Straightforward Android integration
Koin vs. Dagger overview
• Koin pros:
• Less boilerplate. Less arcane, easy to learn
• No annotation processing/code gen. Just language features
• Straightforward Android integration
• Nice, simple documentation
Koin vs. Dagger overview
• Koin pros:
• Less boilerplate. Less arcane, easy to learn
• No annotation processing/code gen. Just language features
• Straightforward Android integration
• Nice, simple documentation
• Build speed (?)
Koin vs. Dagger overview
• Koin pros:
• Less boilerplate. Less arcane, easy to learn
• No annotation processing/code gen. Just language features
• Straightforward Android integration
• Nice, simple documentation
• Build speed (?)
• Koin cons:
Koin vs. Dagger overview
• Koin pros:
• Less boilerplate. Less arcane, easy to learn
• No annotation processing/code gen. Just language features
• Straightforward Android integration
• Nice, simple documentation
• Build speed (?)
• Koin cons:
• Runtime dependency resolution (though minimal overhead)
Koin vs. Dagger overview
• Koin pros:
• Less boilerplate. Less arcane, easy to learn
• No annotation processing/code gen. Just language features
• Straightforward Android integration
• Nice, simple documentation
• Build speed (?)
• Koin cons:
• Runtime dependency resolution (though minimal overhead)
• Newer, relatively unproven (compared to Dagger)
Is it Production-Ready?
Is it Production-Ready?
• Research didn’t turn up much, but…
Is it Production-Ready?
• Research didn’t turn up much, but…
• Reached v1.0 in Sep (FWIW)
Is it Production-Ready?
• Research didn’t turn up much, but…
• Reached v1.0 in Sep (FWIW)
• The author uses it in several production apps…
Is it Production-Ready?
• Research didn’t turn up much, but…
• Reached v1.0 in Sep (FWIW)
• The author uses it in several production apps…
• Workable team uses it prod, details here: https://
medium.com/@charbgr/bye-bye-dagger-1494118dcd41
Thanks!

Questions/thoughts/
comments?
Twitter: @kiwiandroiddev

Email: kiwiandroiddev@gmail.com

More Related Content

What's hot

Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017Arnaud Giuliani
 
Kotlin: Why Do You Care?
Kotlin: Why Do You Care?Kotlin: Why Do You Care?
Kotlin: Why Do You Care?intelliyole
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScriptNascenia IT
 
Kotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersKotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersBartosz Kosarzycki
 
Introduction to kotlin for android app development gdg ahmedabad dev fest 2017
Introduction to kotlin for android app development   gdg ahmedabad dev fest 2017Introduction to kotlin for android app development   gdg ahmedabad dev fest 2017
Introduction to kotlin for android app development gdg ahmedabad dev fest 2017Hardik Trivedi
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScriptFu Cheng
 
Clojure Fundamentals Course For Beginners
Clojure Fundamentals Course For Beginners Clojure Fundamentals Course For Beginners
Clojure Fundamentals Course For Beginners Paddy Lock
 
Kotlin for Android Development
Kotlin for Android DevelopmentKotlin for Android Development
Kotlin for Android DevelopmentSpeck&Tech
 
Clojure, Plain and Simple
Clojure, Plain and SimpleClojure, Plain and Simple
Clojure, Plain and SimpleBen Mabey
 
Android 101 - Kotlin ( Future of Android Development)
Android 101 - Kotlin ( Future of Android Development)Android 101 - Kotlin ( Future of Android Development)
Android 101 - Kotlin ( Future of Android Development)Hassan Abid
 
Fun with Functional Programming in Clojure
Fun with Functional Programming in ClojureFun with Functional Programming in Clojure
Fun with Functional Programming in ClojureCodemotion
 
JavaFX Dependency Injection with FxContainer
JavaFX Dependency Injection with FxContainerJavaFX Dependency Injection with FxContainer
JavaFX Dependency Injection with FxContainerSrikanth Shenoy
 
Annotation Processing - Demystifying Java's Dark Arts
Annotation Processing - Demystifying Java's Dark ArtsAnnotation Processing - Demystifying Java's Dark Arts
Annotation Processing - Demystifying Java's Dark ArtsJames Kirkbride
 
Javascript Module Patterns
Javascript Module PatternsJavascript Module Patterns
Javascript Module PatternsNicholas Jansma
 
Future-proofing Your JavaScript Apps (Compact edition)
Future-proofing Your JavaScript Apps (Compact edition)Future-proofing Your JavaScript Apps (Compact edition)
Future-proofing Your JavaScript Apps (Compact edition)Addy Osmani
 
Beginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScriptBeginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScriptStoyan Stefanov
 
Kotlin, smarter development for the jvm
Kotlin, smarter development for the jvmKotlin, smarter development for the jvm
Kotlin, smarter development for the jvmArnaud Giuliani
 
Building native Android applications with Mirah and Pindah
Building native Android applications with Mirah and PindahBuilding native Android applications with Mirah and Pindah
Building native Android applications with Mirah and PindahNick Plante
 

What's hot (20)

Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017
 
Kotlin: Why Do You Care?
Kotlin: Why Do You Care?Kotlin: Why Do You Care?
Kotlin: Why Do You Care?
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
 
Kotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersKotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developers
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
 
Introduction to kotlin for android app development gdg ahmedabad dev fest 2017
Introduction to kotlin for android app development   gdg ahmedabad dev fest 2017Introduction to kotlin for android app development   gdg ahmedabad dev fest 2017
Introduction to kotlin for android app development gdg ahmedabad dev fest 2017
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
 
Clojure Fundamentals Course For Beginners
Clojure Fundamentals Course For Beginners Clojure Fundamentals Course For Beginners
Clojure Fundamentals Course For Beginners
 
Kotlin for Android Development
Kotlin for Android DevelopmentKotlin for Android Development
Kotlin for Android Development
 
Clojure, Plain and Simple
Clojure, Plain and SimpleClojure, Plain and Simple
Clojure, Plain and Simple
 
Android 101 - Kotlin ( Future of Android Development)
Android 101 - Kotlin ( Future of Android Development)Android 101 - Kotlin ( Future of Android Development)
Android 101 - Kotlin ( Future of Android Development)
 
Fun with Functional Programming in Clojure
Fun with Functional Programming in ClojureFun with Functional Programming in Clojure
Fun with Functional Programming in Clojure
 
JavaFX Dependency Injection with FxContainer
JavaFX Dependency Injection with FxContainerJavaFX Dependency Injection with FxContainer
JavaFX Dependency Injection with FxContainer
 
Annotation Processing - Demystifying Java's Dark Arts
Annotation Processing - Demystifying Java's Dark ArtsAnnotation Processing - Demystifying Java's Dark Arts
Annotation Processing - Demystifying Java's Dark Arts
 
Javascript Module Patterns
Javascript Module PatternsJavascript Module Patterns
Javascript Module Patterns
 
Future-proofing Your JavaScript Apps (Compact edition)
Future-proofing Your JavaScript Apps (Compact edition)Future-proofing Your JavaScript Apps (Compact edition)
Future-proofing Your JavaScript Apps (Compact edition)
 
Beginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScriptBeginning Object-Oriented JavaScript
Beginning Object-Oriented JavaScript
 
Kotlin, smarter development for the jvm
Kotlin, smarter development for the jvmKotlin, smarter development for the jvm
Kotlin, smarter development for the jvm
 
Kotlin intro
Kotlin introKotlin intro
Kotlin intro
 
Building native Android applications with Mirah and Pindah
Building native Android applications with Mirah and PindahBuilding native Android applications with Mirah and Pindah
Building native Android applications with Mirah and Pindah
 

Similar to Koin Quickstart

Having Fun with Kotlin Android - DILo Surabaya
Having Fun with Kotlin Android - DILo SurabayaHaving Fun with Kotlin Android - DILo Surabaya
Having Fun with Kotlin Android - DILo SurabayaDILo Surabaya
 
Practical tips for building apps with kotlin
Practical tips for building apps with kotlinPractical tips for building apps with kotlin
Practical tips for building apps with kotlinAdit Lal
 
Save time with kotlin in android development
Save time with kotlin in android developmentSave time with kotlin in android development
Save time with kotlin in android developmentAdit Lal
 
Kotlin for Android devs
Kotlin for Android devsKotlin for Android devs
Kotlin for Android devsAdit Lal
 
From Java to Kotlin - The first month in practice
From Java to Kotlin - The first month in practiceFrom Java to Kotlin - The first month in practice
From Java to Kotlin - The first month in practiceStefanTomm
 
Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I Atif AbbAsi
 
Kotlin for Android - Vali Iorgu - mRready
Kotlin for Android - Vali Iorgu - mRreadyKotlin for Android - Vali Iorgu - mRready
Kotlin for Android - Vali Iorgu - mRreadyMobileAcademy
 
Building Mobile Apps with Android
Building Mobile Apps with AndroidBuilding Mobile Apps with Android
Building Mobile Apps with AndroidKurt Renzo Acosta
 
Kotlin for Android Developers - 3
Kotlin for Android Developers - 3Kotlin for Android Developers - 3
Kotlin for Android Developers - 3Mohamed Nabil, MSc.
 
A TypeScript Fans KotlinJS Adventures
A TypeScript Fans KotlinJS AdventuresA TypeScript Fans KotlinJS Adventures
A TypeScript Fans KotlinJS AdventuresGarth Gilmour
 
Kotlin / Android Update
Kotlin / Android UpdateKotlin / Android Update
Kotlin / Android UpdateGarth Gilmour
 
Writing Kotlin Multiplatform libraries that your iOS teammates are gonna love
Writing Kotlin Multiplatform libraries that your iOS teammates are gonna loveWriting Kotlin Multiplatform libraries that your iOS teammates are gonna love
Writing Kotlin Multiplatform libraries that your iOS teammates are gonna loveAndré Oriani
 
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...Tudor Dragan
 
Coroutines for Kotlin Multiplatform in Practise
Coroutines for Kotlin Multiplatform in PractiseCoroutines for Kotlin Multiplatform in Practise
Coroutines for Kotlin Multiplatform in PractiseChristian Melchior
 
Rapid Web API development with Kotlin and Ktor
Rapid Web API development with Kotlin and KtorRapid Web API development with Kotlin and Ktor
Rapid Web API development with Kotlin and KtorTrayan Iliev
 
Android & Kotlin - The code awakens #01
Android & Kotlin - The code awakens #01Android & Kotlin - The code awakens #01
Android & Kotlin - The code awakens #01Omar Miatello
 
Kotlin+MicroProfile: Ensinando 20 anos para uma linguagem nova
Kotlin+MicroProfile: Ensinando 20 anos para uma linguagem novaKotlin+MicroProfile: Ensinando 20 anos para uma linguagem nova
Kotlin+MicroProfile: Ensinando 20 anos para uma linguagem novaVíctor Leonel Orozco López
 

Similar to Koin Quickstart (20)

Having Fun with Kotlin Android - DILo Surabaya
Having Fun with Kotlin Android - DILo SurabayaHaving Fun with Kotlin Android - DILo Surabaya
Having Fun with Kotlin Android - DILo Surabaya
 
Practical tips for building apps with kotlin
Practical tips for building apps with kotlinPractical tips for building apps with kotlin
Practical tips for building apps with kotlin
 
Save time with kotlin in android development
Save time with kotlin in android developmentSave time with kotlin in android development
Save time with kotlin in android development
 
Kotlin for Android devs
Kotlin for Android devsKotlin for Android devs
Kotlin for Android devs
 
From Java to Kotlin - The first month in practice
From Java to Kotlin - The first month in practiceFrom Java to Kotlin - The first month in practice
From Java to Kotlin - The first month in practice
 
Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I
 
Kotlin for Android - Vali Iorgu - mRready
Kotlin for Android - Vali Iorgu - mRreadyKotlin for Android - Vali Iorgu - mRready
Kotlin for Android - Vali Iorgu - mRready
 
Building Mobile Apps with Android
Building Mobile Apps with AndroidBuilding Mobile Apps with Android
Building Mobile Apps with Android
 
Fall in love with Kotlin
Fall in love with KotlinFall in love with Kotlin
Fall in love with Kotlin
 
Kotlin for Android Developers - 3
Kotlin for Android Developers - 3Kotlin for Android Developers - 3
Kotlin for Android Developers - 3
 
A TypeScript Fans KotlinJS Adventures
A TypeScript Fans KotlinJS AdventuresA TypeScript Fans KotlinJS Adventures
A TypeScript Fans KotlinJS Adventures
 
Kotlin / Android Update
Kotlin / Android UpdateKotlin / Android Update
Kotlin / Android Update
 
Introduction to Kotlin - Android KTX
Introduction to Kotlin - Android KTXIntroduction to Kotlin - Android KTX
Introduction to Kotlin - Android KTX
 
Writing Kotlin Multiplatform libraries that your iOS teammates are gonna love
Writing Kotlin Multiplatform libraries that your iOS teammates are gonna loveWriting Kotlin Multiplatform libraries that your iOS teammates are gonna love
Writing Kotlin Multiplatform libraries that your iOS teammates are gonna love
 
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
 
Coroutines for Kotlin Multiplatform in Practise
Coroutines for Kotlin Multiplatform in PractiseCoroutines for Kotlin Multiplatform in Practise
Coroutines for Kotlin Multiplatform in Practise
 
Rapid Web API development with Kotlin and Ktor
Rapid Web API development with Kotlin and KtorRapid Web API development with Kotlin and Ktor
Rapid Web API development with Kotlin and Ktor
 
Android & Kotlin - The code awakens #01
Android & Kotlin - The code awakens #01Android & Kotlin - The code awakens #01
Android & Kotlin - The code awakens #01
 
Kotlin+MicroProfile: Ensinando 20 anos para uma linguagem nova
Kotlin+MicroProfile: Ensinando 20 anos para uma linguagem novaKotlin+MicroProfile: Ensinando 20 anos para uma linguagem nova
Kotlin+MicroProfile: Ensinando 20 anos para uma linguagem nova
 
從零開始學 Android
從零開始學 Android從零開始學 Android
從零開始學 Android
 

Recently uploaded

Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 

Recently uploaded (20)

Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 

Koin Quickstart

  • 1. Koin Quickstart Matt Clarke - Auckland Android Community - Dec 2018
  • 3. What is Koin? • From insert-koin.io:
  • 4. What is Koin? • From insert-koin.io: • A pragmatic lightweight dependency injection framework for Kotlin developers.
  • 5. What is Koin? • From insert-koin.io: • A pragmatic lightweight dependency injection framework for Kotlin developers. • Written in pure Kotlin, using functional resolution only: no proxy, no code generation, no reflection.
  • 6. What is Koin? • From insert-koin.io: • A pragmatic lightweight dependency injection framework for Kotlin developers. • Written in pure Kotlin, using functional resolution only: no proxy, no code generation, no reflection. • Koin is a DSL, a light container and a pragmatic API
  • 8. What is Koin? public class Person { private String name; private int age = 0; public Person(String name, int age) { this.name = name; this.age = age; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Person person = (Person) o; if (name != null ? !name.equals(person.name) : person.name != null) return false; if (age != 0 ? age != person.age : person.age != 0) return false; } @Override public int hashCode() { int result = name != null ? name.hashCode() : 0; result = 31 * result + age; return result; } @Override public String toString() { return "Person{" + "name='" + name + ''' + ", age='" + age + ''' + '}'; } }
  • 9. What is Koin? data class Person(var name: String, var age: Int)
  • 10. What is Koin? data class Person(var name: String, var age: Int) i.e. “Koin is to Dagger as Kotlin is to Java”
  • 12. Deep(er) dive: How does any of this work?
  • 13. Deep(er) dive: How does any of this work? val postModule = module { single { PostPresenter(get()) } }
  • 14. Deep(er) dive: How does any of this work? val postModule = module { single { PostPresenter(get()) } }
  • 15. How does any of this work?
  • 16. How does any of this work? /** * Create a Module * Gather definitions * @param path : Path of the module * @param createOnStart : module definitions will be tagged as `createOnStart` * @param override : allow all definitions from module to override definitions */ fun module( path: String = Path.ROOT, createOnStart: Boolean = false, override: Boolean = false, definition: ModuleDefinition.() -> Unit ): Module = { koinContext -> ModuleDefinition(path, createOnStart, override, koinContext).apply(definition) } org/koin/dsl/module/Module.kt
  • 17. How does any of this work? /** * Create a Module * Gather definitions * @param path : Path of the module * @param createOnStart : module definitions will be tagged as `createOnStart` * @param override : allow all definitions from module to override definitions */ fun module( path: String = Path.ROOT, createOnStart: Boolean = false, override: Boolean = false, definition: ModuleDefinition.() -> Unit ): Module = { koinContext -> ModuleDefinition(path, createOnStart, override, koinContext).apply(definition) } org/koin/dsl/module/Module.kt
  • 18. How does any of this work? /** * Create a Module * Gather definitions * @param path : Path of the module * @param createOnStart : module definitions will be tagged as `createOnStart` * @param override : allow all definitions from module to override definitions */ fun module( path: String = Path.ROOT, createOnStart: Boolean = false, override: Boolean = false, definition: ModuleDefinition.() -> Unit ): Module = { koinContext -> ModuleDefinition(path, createOnStart, override, koinContext).apply(definition) } org/koin/dsl/module/Module.kt
  • 19. How does any of this work?
  • 20. How does any of this work? kotlinlang.org/docs/reference/lambdas.html
  • 21. How does any of this work?
  • 22. How does any of this work? val postModule = module { single { PostPresenter(get()) } }
  • 23. How does any of this work? val postModule: Module = module(definition = { single { PostPresenter(get()) } })
  • 24. How does any of this work? val postModule: Module = module(definition = { single { PostPresenter(get()) } })
  • 25. How does any of this work?
  • 26. How does any of this work? /** * Create a Module * Gather definitions * @param path : Path of the module * @param createOnStart : module definitions will be tagged as `createOnStart` * @param override : allow all definitions from module to override definitions */ fun module( path: String = Path.ROOT, createOnStart: Boolean = false, override: Boolean = false, definition: ModuleDefinition.() -> Unit ): Module = { koinContext -> ModuleDefinition(path, createOnStart, override, koinContext).apply(definition) } org/koin/dsl/module/Module.kt
  • 27. How does any of this work? /** * Create a Module * Gather definitions * @param path : Path of the module * @param createOnStart : module definitions will be tagged as `createOnStart` * @param override : allow all definitions from module to override definitions */ fun module( path: String = Path.ROOT, createOnStart: Boolean = false, override: Boolean = false, definition: ModuleDefinition.() -> Unit ): Module = { koinContext -> ModuleDefinition(path, createOnStart, override, koinContext).apply(definition) } org/koin/dsl/module/Module.kt
  • 28. How does any of this work? val postModule: Module = module(definition = { single { PostPresenter(get()) } })
  • 29. How does any of this work? val postModule: Module = module(definition = { this.single { PostPresenter(get()) } })
  • 30. How does any of this work? val postModule: Module = module(definition = { this.single { PostPresenter(get()) } })
  • 31. How does any of this work?
  • 32. How does any of this work? /** * Provide a single instance definition * (unique instance) * * @param name * @param createOnStart - need to be created at start * @param override - allow definition override * @param definition */ inline fun <reified T : Any> single( name: String = "", createOnStart: Boolean = false, override: Boolean = false, noinline definition: Definition<T> ): BeanDefinition<T> { return provide(name, createOnStart, override, Kind.Single, definition) } org/koin/dsl/context/ModuleDefinition.kt
  • 38. What about this? /** * Activity displaying the list of posts */ class PostActivity : AppCompatActivity(), PostView { private val presenter: PostPresenter by inject() // ...
  • 39. What about this? /** * Activity displaying the list of posts */ class PostActivity : AppCompatActivity(), PostView { private val presenter: PostPresenter by inject() // ...
  • 41. No magic • Koin takes full advantage of Kotlin’s adv. language features
  • 42. No magic • Koin takes full advantage of Kotlin’s adv. language features • E.g. reified generics, lambdas with receivers, type inference
  • 43. No magic • Koin takes full advantage of Kotlin’s adv. language features • E.g. reified generics, lambdas with receivers, type inference • Less opaque/magical than annotation processing pipeline for application developers
  • 45. Testability? // Just tag your class with KoinTest to unlock your testing power class SimpleTest : KoinTest { // lazy inject BusinessService into property val service : BusinessService by inject() @Test fun myTest() { // You can start your Koin configuration startKoin(myModules) // or directly get any instance val service : BusinessService = get() // Don't forget to close it at the end closeKoin() } }
  • 47. What about Scopes? val appModule = module { // single instance of HelloRepository single<HelloRepository> { HelloRepositoryImpl() } // Scoped MyScopePresenter instance scope("session") { MyScopePresenter(get())} }
  • 49. What about Scopes? class MyScopeActivity : AppCompatActivity() { // inject MyScopePresenter from "session" scope val scopePresenter: MyScopePresenter by inject() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_simple) // bind "session" scope to component lifecycle bindScope(getOrCreateScope("session")) //... } }
  • 50. Koin vs. Dagger overview
  • 51. Koin vs. Dagger overview • Koin pros:
  • 52. Koin vs. Dagger overview • Koin pros: • Less boilerplate. Less arcane, easy to learn
  • 53. Koin vs. Dagger overview • Koin pros: • Less boilerplate. Less arcane, easy to learn • No annotation processing/code gen. Just language features
  • 54. Koin vs. Dagger overview • Koin pros: • Less boilerplate. Less arcane, easy to learn • No annotation processing/code gen. Just language features • Straightforward Android integration
  • 55. Koin vs. Dagger overview • Koin pros: • Less boilerplate. Less arcane, easy to learn • No annotation processing/code gen. Just language features • Straightforward Android integration • Nice, simple documentation
  • 56. Koin vs. Dagger overview • Koin pros: • Less boilerplate. Less arcane, easy to learn • No annotation processing/code gen. Just language features • Straightforward Android integration • Nice, simple documentation • Build speed (?)
  • 57. Koin vs. Dagger overview • Koin pros: • Less boilerplate. Less arcane, easy to learn • No annotation processing/code gen. Just language features • Straightforward Android integration • Nice, simple documentation • Build speed (?) • Koin cons:
  • 58. Koin vs. Dagger overview • Koin pros: • Less boilerplate. Less arcane, easy to learn • No annotation processing/code gen. Just language features • Straightforward Android integration • Nice, simple documentation • Build speed (?) • Koin cons: • Runtime dependency resolution (though minimal overhead)
  • 59. Koin vs. Dagger overview • Koin pros: • Less boilerplate. Less arcane, easy to learn • No annotation processing/code gen. Just language features • Straightforward Android integration • Nice, simple documentation • Build speed (?) • Koin cons: • Runtime dependency resolution (though minimal overhead) • Newer, relatively unproven (compared to Dagger)
  • 61. Is it Production-Ready? • Research didn’t turn up much, but…
  • 62. Is it Production-Ready? • Research didn’t turn up much, but… • Reached v1.0 in Sep (FWIW)
  • 63. Is it Production-Ready? • Research didn’t turn up much, but… • Reached v1.0 in Sep (FWIW) • The author uses it in several production apps…
  • 64. Is it Production-Ready? • Research didn’t turn up much, but… • Reached v1.0 in Sep (FWIW) • The author uses it in several production apps… • Workable team uses it prod, details here: https:// medium.com/@charbgr/bye-bye-dagger-1494118dcd41