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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
ROYCE MARS
January 07, 2017
Programming
1
480
DataArt & GDG - IT NonStop 2016 - Dagger 2
ROYCE MARS
January 07, 2017
Tweet
Share
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.1k
GDG Ternopil - Mobile Applications Architecture
roycemars
1
1.7k
Ciklum & GDG Dnipro - Dagger 2
roycemars
1
1.4k
Architecture Components - IT Talk, Together With Google
roycemars
1
960
Architecture Components - Build your app right way and enjoy IT! :) - GDG Kharkiv-Center
roycemars
1
500
Architecture Components - IT Step
roycemars
1
410
Quick Look at Design Patterns - GDG Dnipro-Art
roycemars
2
520
Jump into cross-platform development with Firebase - GDG Kharkiv-Center
roycemars
1
540
Ciklum & GDG Dnipro - Android N Security Overview
roycemars
1
340
Other Decks in Programming
See All in Programming
Fluid Templating in TYPO3 14
s2b
0
130
AI時代の認知負荷との向き合い方
optfit
0
160
Data-Centric Kaggle
isax1015
2
770
16年目のピクシブ百科事典を支える最新の技術基盤 / The Modern Tech Stack Powering Pixiv Encyclopedia in its 16th Year
ahuglajbclajep
5
1k
今こそ知るべき耐量子計算機暗号(PQC)入門 / PQC: What You Need to Know Now
mackey0225
3
380
責任感のあるCloudWatchアラームを設計しよう
akihisaikeda
3
170
HTTPプロトコル正しく理解していますか? 〜かわいい猫と共に学ぼう。ฅ^•ω•^ฅ ニャ〜
hekuchan
2
690
20260127_試行錯誤の結晶を1冊に。著者が解説 先輩データサイエンティストからの指南書 / author's_commentary_ds_instructions_guide
nash_efp
1
970
dchart: charts from deck markup
ajstarks
3
990
AI & Enginnering
codelynx
0
110
CSC307 Lecture 08
javiergs
PRO
0
670
AIによる開発の民主化を支える コンテキスト管理のこれまでとこれから
mulyu
3
290
Featured
See All Featured
A Tale of Four Properties
chriscoyier
162
24k
Exploring anti-patterns in Rails
aemeredith
2
250
The Limits of Empathy - UXLibs8
cassininazir
1
210
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
1
1.4k
So, you think you're a good person
axbom
PRO
2
1.9k
The Mindset for Success: Future Career Progression
greggifford
PRO
0
240
New Earth Scene 8
popppiees
1
1.5k
Automating Front-end Workflow
addyosmani
1371
200k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
117
110k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.4k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
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