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
DataArt & GDG - IT NonStop 2016 - Dagger 2
Search
Royce Mars
January 07, 2017
Programming
530
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
DataArt & GDG - IT NonStop 2016 - Dagger 2
Royce Mars
January 07, 2017
More Decks by Royce Mars
See All by Royce Mars
GDG Ukraine - Post I/O Tour 2018 - Kyiv, Dnipro, Kharkiv, Cherkasy, Kremenchuk, Poltava, Kropyvnytskyy - Google Cloud & Firebase
roycemars
1
3.2k
GDG Ternopil - Mobile Applications Architecture
roycemars
1
1.8k
Ciklum & GDG Dnipro - Dagger 2
roycemars
1
1.4k
Architecture Components - IT Talk, Together With Google
roycemars
1
1k
Architecture Components - Build your app right way and enjoy IT! :) - GDG Kharkiv-Center
roycemars
1
550
Architecture Components - IT Step
roycemars
1
460
Quick Look at Design Patterns - GDG Dnipro-Art
roycemars
2
580
Jump into cross-platform development with Firebase - GDG Kharkiv-Center
roycemars
1
600
Ciklum & GDG Dnipro - Android N Security Overview
roycemars
1
350
Other Decks in Programming
See All in Programming
Creating Composable Callables in Contemporary C++
rollbear
0
180
Contextとはなにか
chiroruxx
1
390
The Bowling Game- From Imperative to Functional Programming - Part 1
philipschwarz
PRO
0
230
Dataformのリポジトリを立ち上げるときにまずやること / dataform-day0-2026
snhryt
0
210
TSKaigi Night Talks 2026_TypeScriptでサプライチェーンの整合性を型に閉じ込める
geekplus_tech
0
420
LLM本来の能力を解き放つサンドボックス技術とAI民主化への適用
yukukotani
3
4.8k
AIで効率化できた業務・日常
ochtum
0
160
20260623_Loop Engineeringで自分の分身の問い合わせBotを作る
ryugen04
0
110
Performance Engineering for Everyone
elenatanasoiu
0
250
Mujeres en SEO Summit 2026 - Greatest Disaster Hits en Web Performance
guaca
0
230
AI 輔助遺留系統現代化的經驗分享
jame2408
1
1.1k
LaravelLive Japan の裏方のすべて — 第188回 PHP勉強会@東京 (2026-06-24)
suguruooki
2
140
Featured
See All Featured
Building a Scalable Design System with Sketch
lauravandoore
463
34k
Marketing to machines
jonoalderson
1
5.5k
Deep Space Network (abreviated)
tonyrice
0
220
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
630
Between Models and Reality
mayunak
4
360
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
760
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.9k
What does AI have to do with Human Rights?
axbom
PRO
1
2.2k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
6k
New Earth Scene 8
popppiees
3
2.4k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
180
Transcript
Dagger 2 Лечим зависимости по методике :) Докладчик: Constantine Mars
Senior Developer @ DataArt, Co-Organizer @ GDG Dnipro
Dependency Injection Что, зачем, и когда это нужно
Создание классов порождает... • Композиция - не наследование • Ссылки
не будут пустовать
Возможность создавать объекты...
Создавать разные объекты...
Комбинировать объекты (“композиция” объектов)...
Использовать наследование и разнообразить композицию...
И… Зависимости Car depends on Engine. Engines may vary. We’ll
probably need different engines for testing and production
Dagger and JSR-330 Аннотация @Inject
немного еще НЕ истории • Dagger 2 - Google, Greg
Kick • Dagger - Square, Jake Wharthon • Guice - Google, Jesse Wilson
Inversion of Control Invert your dependencies
Reflection vs Compile time • Dagger 2 vs Dagger 1
JSR-330
Puttin’ there piece of magic...
Обратите внимание на конструктор по умолчанию
А вот конструктор с параметрами - хорошее место для модификаций...
И все же, как это заставить работать?
Структура инжекции Dagger 2.0 Модули, Компоненты
Компоненты и модули Pic. author - Miroslaw Stanek from Azimo
http://frogermcs.github.io/dagger-graph-creation-performance/
Модуль… next slide, please
Модуль - коллекция генераторов
Компонент - хост для модулей, инжектор для классов, корень дерева
зависимостей
То же самое, только с красными стрелочками :]
Инициализация компонента generated code used
Inject This! :) Puttin’ magic will work only after injection…
;)
Inject This! :)
Custom Scopes и эффективное управление памятью
Жизненный цикл объектов Pic. author - Miroslaw Stanek from Azimo
http://frogermcs.github.io/dagger-graph-creation-performance/
И еще раз та же матрешка Компонент имеет область жизни
(scope) Pic. author - Miroslaw Stanek from Azimo http://frogermcs.github.io/dagger-graph-creation-performance/
This mysterious ‘plus’...
Объявление суп-компонента
Но ведь там был модуль! =)
Добавление субкомпонента к корню дерева зависимостей
Как управлять временем жизни субкомпонентов? Pic. author - Miroslaw Stanek
from Azimo http://frogermcs.github.io/dagger-graph-creation-performance/
Аннотация @Scope
@ActivityScope
@ActivityScope
@UserScope
@UserScope
@UserScope
Напоследок… Что инжектить? • Модули демо-данных • Презентеры • Синглетоны
• Тестовые реализации классов • ...Все остальное что инстанцируется и создает зависимости :)
Home readings Sample code: https://github.com/c-mars/Dagger2Scopes.git • Fernando Cejas “Tasting Dagger
2 on Android”: http://fernandocejas.com/2015/04/11/tasting-dagger-2-on-android/ • • Miroslaw Stanek “Dagger2 - graph creation performance: http://frogermcs.github.io/dagger-graph-creation-performance/ • • Dagger2 official page: http://google.github.io/dagger/
Смысл кода Как мы организовали быструю Agile-разработку с использованием Mock-модулей,
и в итоге обгонали сервер-сайд
Всем спасибо! Contact me:
[email protected]
+ConstantineMars