SlideShare a Scribd company logo
1 of 33
Download to read offline
Ƅ Rekimoto Lab. at University of Tokyo
(Samura Lab. at Akashi-NCT)
Enginner at Wantedly, Inc.
Mentor at Life is Tech, Inc.
Ruby
Ruby on Rails
JavaScript
Android
Design
Others
Skill Ratio
Depdendency
Injection
依 存 性 注 入
ディペンデンシー・インジェクション
依存性の注入とは、コンポーネント間の依存関係を
プログラムのソースコードから排除し、
外部の設定ファイルなどで注入できるようにする
ソフトウェアパターンである。
依存性の注入 - Wikipedia
共通 component
ふつうのばあい
共通 component
ふつうのばあい
直接参照している
(global 変数,new など)
共通 component
ふつうのばあい
component の機能が少ない…
拡張しよう!
共通 component
ふつうのばあい
_人人人人人人人人_
> 突然の密結合 <
 ̄Y^Y^Y^Y^Y^Y^Y ̄
共通 component
DI する場合
インタフェースを参照する
共通 component
DI する場合
どの実態を利用するか
○ DI コンテナに記述
共通 component
DI のメリット
ここは単体テストで OK
共通 component の
モック
DI のメリット
mock に差し替えると
テストが容易に!
Android
DI をつかおう
JavaScript
Android
DI をつかおう
Dagger2
Android における DI
Sign in
遷移
tweet 取得
Android における DI
Sign in
遷移
tweet 取得
インスタンス変数に保持してると…
○ ライフサイクルに巻き込まれて死ぬ
Android における DI
Sign in
遷移
tweet 取得
DI コンテナ
Android における DI
Sign in
遷移
tweet 取得
DI コンテナ
DI コンテナが User を保持するので
ライフサイクルに巻き込まれない!
DI をつかおう
JavaScript
Browserify
JavaScript における DI
グローバルオブジェクト(window/global)
JavaScript における DI
グローバルオブジェクト(window/global)
_人人人人人人人人人_
> グローバル汚染 <
 ̄Y^Y^Y^Y^Y^Y^Y^Y ̄
JavaScript における DI
グローバルオブジェクト(window/global)
JavaScript における DI
グローバルオブジェクト(window/global)DI コンテナに押し込めて
グローバル汚染を防止
まとめ
DIでグローバル汚染の防止
DIでテスタビリティ向上
DIでモジュールの疎結合化
Android では…
Dagger / Dagger2
JavaScript では…
Browserify / ECMAScript 6
Do you know Dependency Injection ?
Do you know Dependency Injection ?
Do you know Dependency Injection ?

More Related Content

Viewers also liked

Functional Dependency Injection in C#
Functional Dependency Injection in C#Functional Dependency Injection in C#
Functional Dependency Injection in C#Thomas Jaskula
 
Dependency injection - the right way
Dependency injection - the right wayDependency injection - the right way
Dependency injection - the right wayThibaud Desodt
 
Inversion of Control - Introduction and Best Practice
Inversion of Control - Introduction and Best PracticeInversion of Control - Introduction and Best Practice
Inversion of Control - Introduction and Best PracticeLars-Erik Kindblad
 
Eight Signs Your Marketing Content Is Being Wasted, Ignored, Exploited...Or W...
Eight Signs Your Marketing Content Is Being Wasted, Ignored, Exploited...Or W...Eight Signs Your Marketing Content Is Being Wasted, Ignored, Exploited...Or W...
Eight Signs Your Marketing Content Is Being Wasted, Ignored, Exploited...Or W...Heinz Marketing Inc
 
Menú de ajustes en word press
Menú de ajustes en word pressMenú de ajustes en word press
Menú de ajustes en word pressdopamina mexico
 
Entrepreneurial learning carltonbolling
Entrepreneurial learning carltonbollingEntrepreneurial learning carltonbolling
Entrepreneurial learning carltonbollingcircle1315
 
Marketing Channels 101
Marketing Channels 101Marketing Channels 101
Marketing Channels 101Amanda Sutt
 
外匯交易簡介
外匯交易簡介外匯交易簡介
外匯交易簡介samlincnyes
 
Entrepreneurial Lessons 2012
Entrepreneurial Lessons 2012Entrepreneurial Lessons 2012
Entrepreneurial Lessons 2012Sam Beal
 
Travel Turbulence? Apps to the Rescue!
Travel Turbulence? Apps to the Rescue!Travel Turbulence? Apps to the Rescue!
Travel Turbulence? Apps to the Rescue!SAP Concur
 
Is the future of local media hyperlocal?
Is the future of local media hyperlocal?Is the future of local media hyperlocal?
Is the future of local media hyperlocal?mark woodward
 
Europees Hof zet eerste stap in dispuut onverdoofd slachten
Europees Hof zet eerste stap in dispuut onverdoofd slachtenEuropees Hof zet eerste stap in dispuut onverdoofd slachten
Europees Hof zet eerste stap in dispuut onverdoofd slachtenThierry Debels
 
Diffusion of lead user (Presentation)
Diffusion of lead user (Presentation)Diffusion of lead user (Presentation)
Diffusion of lead user (Presentation)punpun
 

Viewers also liked (19)

Functional Dependency Injection in C#
Functional Dependency Injection in C#Functional Dependency Injection in C#
Functional Dependency Injection in C#
 
Dependency injection - the right way
Dependency injection - the right wayDependency injection - the right way
Dependency injection - the right way
 
Inversion of Control - Introduction and Best Practice
Inversion of Control - Introduction and Best PracticeInversion of Control - Introduction and Best Practice
Inversion of Control - Introduction and Best Practice
 
IoC and Mapper in C#
IoC and Mapper in C#IoC and Mapper in C#
IoC and Mapper in C#
 
Eight Signs Your Marketing Content Is Being Wasted, Ignored, Exploited...Or W...
Eight Signs Your Marketing Content Is Being Wasted, Ignored, Exploited...Or W...Eight Signs Your Marketing Content Is Being Wasted, Ignored, Exploited...Or W...
Eight Signs Your Marketing Content Is Being Wasted, Ignored, Exploited...Or W...
 
Menú de ajustes en word press
Menú de ajustes en word pressMenú de ajustes en word press
Menú de ajustes en word press
 
Sljuncana mafija
Sljuncana mafijaSljuncana mafija
Sljuncana mafija
 
Entrepreneurial learning carltonbolling
Entrepreneurial learning carltonbollingEntrepreneurial learning carltonbolling
Entrepreneurial learning carltonbolling
 
Marketing Channels 101
Marketing Channels 101Marketing Channels 101
Marketing Channels 101
 
Boletim (1)
Boletim (1)Boletim (1)
Boletim (1)
 
外匯交易簡介
外匯交易簡介外匯交易簡介
外匯交易簡介
 
Entrepreneurial Lessons 2012
Entrepreneurial Lessons 2012Entrepreneurial Lessons 2012
Entrepreneurial Lessons 2012
 
Travel Turbulence? Apps to the Rescue!
Travel Turbulence? Apps to the Rescue!Travel Turbulence? Apps to the Rescue!
Travel Turbulence? Apps to the Rescue!
 
Ept1 unidad 2
Ept1 unidad 2Ept1 unidad 2
Ept1 unidad 2
 
Новый взгляд на визуализацию информации
Новый взгляд на визуализацию информацииНовый взгляд на визуализацию информации
Новый взгляд на визуализацию информации
 
Is the future of local media hyperlocal?
Is the future of local media hyperlocal?Is the future of local media hyperlocal?
Is the future of local media hyperlocal?
 
Independent Chairman - Research Spotlight
Independent Chairman - Research SpotlightIndependent Chairman - Research Spotlight
Independent Chairman - Research Spotlight
 
Europees Hof zet eerste stap in dispuut onverdoofd slachten
Europees Hof zet eerste stap in dispuut onverdoofd slachtenEuropees Hof zet eerste stap in dispuut onverdoofd slachten
Europees Hof zet eerste stap in dispuut onverdoofd slachten
 
Diffusion of lead user (Presentation)
Diffusion of lead user (Presentation)Diffusion of lead user (Presentation)
Diffusion of lead user (Presentation)
 

Similar to Do you know Dependency Injection ?

FlutterでのWidgetツリーへの状態伝播とアクセス制限の基本戦略
FlutterでのWidgetツリーへの状態伝播とアクセス制限の基本戦略FlutterでのWidgetツリーへの状態伝播とアクセス制限の基本戦略
FlutterでのWidgetツリーへの状態伝播とアクセス制限の基本戦略cch-robo
 
簡単AngularJS(関西AngularJS勉強会)
簡単AngularJS(関西AngularJS勉強会)簡単AngularJS(関西AngularJS勉強会)
簡単AngularJS(関西AngularJS勉強会)Takahiro Maki
 
Swiftで説明する「モナド」:Swiftにおける関数型プログラミングの使い方
Swiftで説明する「モナド」:Swiftにおける関数型プログラミングの使い方Swiftで説明する「モナド」:Swiftにおける関数型プログラミングの使い方
Swiftで説明する「モナド」:Swiftにおける関数型プログラミングの使い方Roy Kim
 
jjug_night_20161121
jjug_night_20161121jjug_night_20161121
jjug_night_20161121Naoya Kojima
 
DiI/DIコンテナを一から学んでみた
DiI/DIコンテナを一から学んでみたDiI/DIコンテナを一から学んでみた
DiI/DIコンテナを一から学んでみたtak
 
アプリでもオブジェクト指向エクササイズ(Potatotips#3)
アプリでもオブジェクト指向エクササイズ(Potatotips#3)アプリでもオブジェクト指向エクササイズ(Potatotips#3)
アプリでもオブジェクト指向エクササイズ(Potatotips#3)Shoichi Matsuda
 
ソフトウェア設計原則【SOLID】を学ぶ #2 インターフェイス分離の原則.pdf
ソフトウェア設計原則【SOLID】を学ぶ #2 インターフェイス分離の原則.pdfソフトウェア設計原則【SOLID】を学ぶ #2 インターフェイス分離の原則.pdf
ソフトウェア設計原則【SOLID】を学ぶ #2 インターフェイス分離の原則.pdf耕二 阿部
 
DI(依存性注入)について
DI(依存性注入)についてDI(依存性注入)について
DI(依存性注入)についてYui Ito
 
ソフトウェア設計原則【SOLID】を学ぶ #3 依存性逆転の原則.pdf
ソフトウェア設計原則【SOLID】を学ぶ #3 依存性逆転の原則.pdfソフトウェア設計原則【SOLID】を学ぶ #3 依存性逆転の原則.pdf
ソフトウェア設計原則【SOLID】を学ぶ #3 依存性逆転の原則.pdf耕二 阿部
 
[デブサミ2012]趣味と実益の脆弱性発見
[デブサミ2012]趣味と実益の脆弱性発見[デブサミ2012]趣味と実益の脆弱性発見
[デブサミ2012]趣味と実益の脆弱性発見Yosuke HASEGAWA
 

Similar to Do you know Dependency Injection ? (11)

FlutterでのWidgetツリーへの状態伝播とアクセス制限の基本戦略
FlutterでのWidgetツリーへの状態伝播とアクセス制限の基本戦略FlutterでのWidgetツリーへの状態伝播とアクセス制限の基本戦略
FlutterでのWidgetツリーへの状態伝播とアクセス制限の基本戦略
 
簡単AngularJS(関西AngularJS勉強会)
簡単AngularJS(関西AngularJS勉強会)簡単AngularJS(関西AngularJS勉強会)
簡単AngularJS(関西AngularJS勉強会)
 
Swiftで説明する「モナド」:Swiftにおける関数型プログラミングの使い方
Swiftで説明する「モナド」:Swiftにおける関数型プログラミングの使い方Swiftで説明する「モナド」:Swiftにおける関数型プログラミングの使い方
Swiftで説明する「モナド」:Swiftにおける関数型プログラミングの使い方
 
AndroidでDIxAOP
AndroidでDIxAOPAndroidでDIxAOP
AndroidでDIxAOP
 
jjug_night_20161121
jjug_night_20161121jjug_night_20161121
jjug_night_20161121
 
DiI/DIコンテナを一から学んでみた
DiI/DIコンテナを一から学んでみたDiI/DIコンテナを一から学んでみた
DiI/DIコンテナを一から学んでみた
 
アプリでもオブジェクト指向エクササイズ(Potatotips#3)
アプリでもオブジェクト指向エクササイズ(Potatotips#3)アプリでもオブジェクト指向エクササイズ(Potatotips#3)
アプリでもオブジェクト指向エクササイズ(Potatotips#3)
 
ソフトウェア設計原則【SOLID】を学ぶ #2 インターフェイス分離の原則.pdf
ソフトウェア設計原則【SOLID】を学ぶ #2 インターフェイス分離の原則.pdfソフトウェア設計原則【SOLID】を学ぶ #2 インターフェイス分離の原則.pdf
ソフトウェア設計原則【SOLID】を学ぶ #2 インターフェイス分離の原則.pdf
 
DI(依存性注入)について
DI(依存性注入)についてDI(依存性注入)について
DI(依存性注入)について
 
ソフトウェア設計原則【SOLID】を学ぶ #3 依存性逆転の原則.pdf
ソフトウェア設計原則【SOLID】を学ぶ #3 依存性逆転の原則.pdfソフトウェア設計原則【SOLID】を学ぶ #3 依存性逆転の原則.pdf
ソフトウェア設計原則【SOLID】を学ぶ #3 依存性逆転の原則.pdf
 
[デブサミ2012]趣味と実益の脆弱性発見
[デブサミ2012]趣味と実益の脆弱性発見[デブサミ2012]趣味と実益の脆弱性発見
[デブサミ2012]趣味と実益の脆弱性発見
 

Recently uploaded

自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer
自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer
自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineerYuki Kikuchi
 
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)UEHARA, Tetsutaro
 
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案sugiuralab
 
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)Hiroki Ichikura
 
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdf
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdfクラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdf
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdfFumieNakayama
 
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdf
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdfAWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdf
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdfFumieNakayama
 
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察 ~Text-to-MusicとText-To-ImageかつImage-to-Music...
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察  ~Text-to-MusicとText-To-ImageかつImage-to-Music...モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察  ~Text-to-MusicとText-To-ImageかつImage-to-Music...
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察 ~Text-to-MusicとText-To-ImageかつImage-to-Music...博三 太田
 
CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?
CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?
CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?akihisamiyanaga1
 
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版) 2024年4月作成
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版) 2024年4月作成業務で生成AIを活用したい人のための生成AI入門講座(社外公開版) 2024年4月作成
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版) 2024年4月作成Hiroshi Tomioka
 

Recently uploaded (9)

自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer
自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer
自分史上一番早い2024振り返り〜コロナ後、仕事は通常ペースに戻ったか〜 by IoT fullstack engineer
 
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)
デジタル・フォレンジックの最新動向(2024年4月27日情洛会総会特別講演スライド)
 
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
 
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
 
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdf
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdfクラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdf
クラウドネイティブなサーバー仮想化基盤 - OpenShift Virtualization.pdf
 
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdf
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdfAWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdf
AWS の OpenShift サービス (ROSA) を使った OpenShift Virtualizationの始め方.pdf
 
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察 ~Text-to-MusicとText-To-ImageかつImage-to-Music...
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察  ~Text-to-MusicとText-To-ImageかつImage-to-Music...モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察  ~Text-to-MusicとText-To-ImageかつImage-to-Music...
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察 ~Text-to-MusicとText-To-ImageかつImage-to-Music...
 
CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?
CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?
CTO, VPoE, テックリードなどリーダーポジションに登用したくなるのはどんな人材か?
 
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版) 2024年4月作成
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版) 2024年4月作成業務で生成AIを活用したい人のための生成AI入門講座(社外公開版) 2024年4月作成
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版) 2024年4月作成
 

Do you know Dependency Injection ?