SlideShare a Scribd company logo
Idiomatic DI in Kotlin
Dmytro Zaitsev
Technical Lead @ Lohika
Dependency Injection
A technique for applying the principle of Inversion of Control
The goal - to achieve separation of concerns in our code
We want to use objects and don’t care about creating them
Dependency Injection
Service Locator
Design pattern used to encapsulate the processes involved in obtaining a
dependency
Acts like a simple runtime linker
Ідіоматична ін'єкція залежностей на Kotlin без фреймворків - UA Mobile2019
Dependency Injection vs Service Locator
Both solve the problem of decoupling our code
Code does not instantiate concrete implementations
Dependency Injection vs Service Locator
With DI, we don’t have direct requests for dependencies
Dependencies are injected by the framework
With SL, our code asks the locator for specific dependencies
Every class that needs an injection has a dependency on the service locator
DI SL
Framework
You
You
Dagger 2
Dagger 2
Fully static compile-time DI framework for Java
Uses AP and codegen to build a dependency graph
“If it compiles, it will work…’’’
Requires lots of boilerplate
Adds up to the build time
Generates lots of code. It may be an overkill for small projects
“Just because big companies or your
friends use a library, it doesn’t mean it
will work for you.
Evaluate it and then go for it.”
Koin & Kodein
Lightweight DI frameworks for Kotlin
Work like Service Locator
No proxy, codegen, introspection, annotation processing
Leverage Kotlin features: delegates, reified generics, inline functions
Simple declarative DSL with idiomatic Kotlin API
Will crush at runtime if it can’t resolve a dependency
Koin
Small (really), pragmatic, concise
Can only be used with Kotlin
Simple natural API
Kodein
Can be used on JVM, Android, JS and Native
Robust
Has tons of features
More verbose, complicated API
So, choose wisely
or…
Create your own solution!
Demo
https://github.com/DmitriyZaitsev/kontainer
Thank you!
@DmitriyZaitsev

More Related Content

PPTX
"Secure Mobile Apps with the Microsoft Identity Platform", Christos Matskas, ...
PPTX
Dependency injection
PPT
Dependency Injection & IoC
PPTX
Dependency Injection And Ioc Containers
PDF
Building Scalable Micro-services with Nodejs
DOCX
Dependency injection& comparative study
PDF
Stateful pattern con Azure Functions
PPS
Introduction To Dependency Injection Using Spring.NET
"Secure Mobile Apps with the Microsoft Identity Platform", Christos Matskas, ...
Dependency injection
Dependency Injection & IoC
Dependency Injection And Ioc Containers
Building Scalable Micro-services with Nodejs
Dependency injection& comparative study
Stateful pattern con Azure Functions
Introduction To Dependency Injection Using Spring.NET

What's hot (10)

PPTX
Choosing an IoC container
PDF
What does it take to be an architect
PDF
iSAQB gathering 2021 keynote - Architectural patterns for rapid, reliable, fr...
PDF
PDF
Api chaining(tm)
PDF
BeAPI API Framework
PPTX
Oleksandr Valetskyy - Become a .NET dependency injection ninja with Ninject
PPTX
Dependency Injection або Don’t call me, I’ll call you
PDF
Clean architecture with Python
PDF
Moved to https://slidr.io/azzazzel/business-wins-in-modularity-microservices-...
Choosing an IoC container
What does it take to be an architect
iSAQB gathering 2021 keynote - Architectural patterns for rapid, reliable, fr...
Api chaining(tm)
BeAPI API Framework
Oleksandr Valetskyy - Become a .NET dependency injection ninja with Ninject
Dependency Injection або Don’t call me, I’ll call you
Clean architecture with Python
Moved to https://slidr.io/azzazzel/business-wins-in-modularity-microservices-...

Similar to Ідіоматична ін'єкція залежностей на Kotlin без фреймворків - UA Mobile2019 (20)

PPTX
Dependency Inversion Principle
PPTX
Introduction to dependency injection in Scala (Play)
PDF
Dependency injection Drupal Camp Wrocław 2014
PPTX
Dependency injection presentation
PPTX
Dirigible powered by Orion for Cloud Development (EclipseCon EU 2015)
PPTX
Introduction to Spring Framework
 
PPTX
Dip(dependency inversion principle) presentation
PPTX
Polaris presentation ioc - code conference
PDF
Meningkatkan SOC dan Reusabillity Kode dengan Duo DI - Sidiq Permana (CIO Nus...
PPTX
Mobile App Architectures & Coding guidelines
PPTX
Introduction to angular | Concepts and Environment setup
PPTX
What's new in Angular 2?
PDF
Revolution in integration!
PPTX
Spring Web Presentation - Framework and Its Ecosystem
PDF
[CocoaHeads Tricity] Andrzej Dąbrowski - Dependency injection and testable ar...
PDF
Patterns and practices for building enterprise-scale HTML5 apps
PPTX
Di with dagger2 in android
PDF
Fed London - January 2015
PDF
Crafting ColdFusion Applications like an Architect
PPTX
Igor Kochetov "What is wrong with Dependency Injection? Myths and Truths"
Dependency Inversion Principle
Introduction to dependency injection in Scala (Play)
Dependency injection Drupal Camp Wrocław 2014
Dependency injection presentation
Dirigible powered by Orion for Cloud Development (EclipseCon EU 2015)
Introduction to Spring Framework
 
Dip(dependency inversion principle) presentation
Polaris presentation ioc - code conference
Meningkatkan SOC dan Reusabillity Kode dengan Duo DI - Sidiq Permana (CIO Nus...
Mobile App Architectures & Coding guidelines
Introduction to angular | Concepts and Environment setup
What's new in Angular 2?
Revolution in integration!
Spring Web Presentation - Framework and Its Ecosystem
[CocoaHeads Tricity] Andrzej Dąbrowski - Dependency injection and testable ar...
Patterns and practices for building enterprise-scale HTML5 apps
Di with dagger2 in android
Fed London - January 2015
Crafting ColdFusion Applications like an Architect
Igor Kochetov "What is wrong with Dependency Injection? Myths and Truths"

More from UA Mobile (20)

PDF
Designing iOS+Android project without using multiplatform frameworks - UA Mob...
PDF
Декларативное программирование клиент-серверных приложений на андроид - UA Mo...
PDF
Leave your Room behind - UA Mobile 2019
PDF
OpenId and OAuth2: Rear, Medium, Well Done - UA Mobile 2019
PDF
Google Wear OS watch faces and applications development - UA Mobile 2019
PDF
Історія декількох проектів та що в них пішло не так - UA Mobile 2019
PDF
Working effectively with ViewModels and TDD - UA Mobile 2019
PDF
Managing State in Reactive applications - UA Mobile 2019
PDF
Актуальні практики дизайну мобільних додатків - UA Mobile 2019
PDF
До чого прикладати Docker в Android? - UA Mobile 2019
PDF
Building your Flutter apps using Redux - UA Mobile 2019
PDF
Optional. Tips and Tricks - UA Mobile 2019
PDF
Designing iOS+Android project without using multiplatform frameworks - UA Mob...
PDF
Бібліотеки та Інструменти на сторожі коду - UA Mobile 2019
PDF
Flutter: No more boring apps! - UA Mobile 2019
PDF
Долаючи прірву між дизайнерами та розробниками - UA Mobile 2019
PDF
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
PDF
Sceneform SDK на практиці - UA Mobile 2019
PDF
Coroutines in Kotlin. UA Mobile 2017.
PDF
Augmented reality on Android. UA Mobile 2017.
Designing iOS+Android project without using multiplatform frameworks - UA Mob...
Декларативное программирование клиент-серверных приложений на андроид - UA Mo...
Leave your Room behind - UA Mobile 2019
OpenId and OAuth2: Rear, Medium, Well Done - UA Mobile 2019
Google Wear OS watch faces and applications development - UA Mobile 2019
Історія декількох проектів та що в них пішло не так - UA Mobile 2019
Working effectively with ViewModels and TDD - UA Mobile 2019
Managing State in Reactive applications - UA Mobile 2019
Актуальні практики дизайну мобільних додатків - UA Mobile 2019
До чого прикладати Docker в Android? - UA Mobile 2019
Building your Flutter apps using Redux - UA Mobile 2019
Optional. Tips and Tricks - UA Mobile 2019
Designing iOS+Android project without using multiplatform frameworks - UA Mob...
Бібліотеки та Інструменти на сторожі коду - UA Mobile 2019
Flutter: No more boring apps! - UA Mobile 2019
Долаючи прірву між дизайнерами та розробниками - UA Mobile 2019
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
Sceneform SDK на практиці - UA Mobile 2019
Coroutines in Kotlin. UA Mobile 2017.
Augmented reality on Android. UA Mobile 2017.

Recently uploaded (6)

PDF
6-UseCfgfhgfhgfhgfhgfhfhhaseActivity.pdf
DOC
证书学历UoA毕业证,澳大利亚中汇学院毕业证国外大学毕业证
PPTX
ASMS Telecommunication company Profile
DOC
Camb毕业证学历认证,格罗斯泰斯特主教大学毕业证仿冒文凭毕业证
PDF
heheheueueyeyeyegehehehhehshMedia-Literacy.pdf
PDF
Lesson 13- HEREDITY _ pedSAWEREGFVCXZDSASEWFigree.pdf
6-UseCfgfhgfhgfhgfhgfhfhhaseActivity.pdf
证书学历UoA毕业证,澳大利亚中汇学院毕业证国外大学毕业证
ASMS Telecommunication company Profile
Camb毕业证学历认证,格罗斯泰斯特主教大学毕业证仿冒文凭毕业证
heheheueueyeyeyegehehehhehshMedia-Literacy.pdf
Lesson 13- HEREDITY _ pedSAWEREGFVCXZDSASEWFigree.pdf

Ідіоматична ін'єкція залежностей на Kotlin без фреймворків - UA Mobile2019