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
Dependency Injection はじめの一歩 / 20191024 C#Tokyo
Search
Taka
October 24, 2019
Programming
0
860
Dependency Injection はじめの一歩 / 20191024 C#Tokyo
2019/10/24
.NET Core 3.0 リリース記念 C# Tokyo 2019/10 発表資料
Taka
October 24, 2019
Tweet
Share
More Decks by Taka
See All by Taka
フロントエンド初心者が Blazorを使ってみた / 20220428 C#Tokyo
takahiro901
0
480
HoloLens 2なしでも MRを楽しむ!
takahiro901
0
1.1k
BlazorのPWAを使ってみた / Tried using PWA
takahiro901
0
1.4k
C#勉強法: コンソールでアプリを作ろう / 20190910 C# Tokyo
takahiro901
0
810
Xamarin.Formsで自分用の家計簿アプリを作ってみた / 20190831 JXUG
takahiro901
0
950
プログラミング初心者が Xamarin.Formsやってみた / 20180523 JXUG
takahiro901
0
450
Other Decks in Programming
See All in Programming
CSC307 Lecture 06
javiergs
PRO
0
690
フロントエンド開発の勘所 -複数事業を経験して見えた判断軸の違い-
heimusu
7
2.8k
Apache Iceberg V3 and migration to V3
tomtanaka
0
170
[KNOTS 2026登壇資料]AIで拡張‧交差する プロダクト開発のプロセス および携わるメンバーの役割
hisatake
0
290
ぼくの開発環境2026
yuzneri
0
240
今から始めるClaude Code超入門
448jp
8
9k
登壇資料を作る時に意識していること #登壇資料_findy
konifar
4
1.6k
KIKI_MBSD Cybersecurity Challenges 2025
ikema
0
1.3k
責任感のあるCloudWatchアラームを設計しよう
akihisaikeda
3
180
AIで開発はどれくらい加速したのか?AIエージェントによるコード生成を、現場の評価と研究開発の評価の両面からdeep diveしてみる
daisuketakeda
1
2.5k
Amazon Bedrockを活用したRAGの品質管理パイプライン構築
tosuri13
5
770
CSC307 Lecture 03
javiergs
PRO
1
490
Featured
See All Featured
BBQ
matthewcrist
89
10k
Discover your Explorer Soul
emna__ayadi
2
1.1k
The Limits of Empathy - UXLibs8
cassininazir
1
220
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.6k
Practical Orchestrator
shlominoach
191
11k
What's in a price? How to price your products and services
michaelherold
247
13k
Un-Boring Meetings
codingconduct
0
200
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
270
Code Review Best Practice
trishagee
74
20k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.1k
jQuery: Nuts, Bolts and Bling
dougneiner
65
8.4k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Transcript
Dependency Injection はじめの一歩 2019/10/24 .NET Core 3.0 リリース記念 C# Tokyo
2019/10
自己紹介 • ふるかわ @futa_ttjh • 都内IT企業勤務のエンジニア • C#、Xamarin.Formsが好き • Blog
https://takataka430.hatenablog.com/ 2
本発表について Dependency Injectionについて、自分が調べて理解している、と思っている範囲のこと を発表します。 コードよりも図が多め 間違いなどあれば教えてください! 3
Today’s Goal 以下のような方にDependency Injectionについてイメージしてもらう • Dependency Injection 初めて聞いた • Dependency
Injection 聞いたことあるけどよくわからない • 依存性の注入?? 何それ怖い・・・ 4
アプリを作る上で大事なこと 変化に強いことが重要! 機能の追加 顧客からの要望 外部環境の変化 ・・・etc 5
変化に強いとは??? 6
変化に弱い→クラス間で直接の依存関係がある場合 7 HogeHoge Class Contoso Class 直接利用 Contoso Class が必要
public class HogeHoge { Contoso contoso = new Contoso(); ・ ・ ・ コードで書くと
依存している事によるデメリット ・あるクラスが特定の他のクラスに強く結びついている →カスタマイズが難しい ・利用している外部のクラスがないと動かない →単体テストがやりにくい 8
Dependency Injection(DI) とは あるクラスが別のクラスを利用するとき、インスタンスを外部から引き渡す仕組み(直接 new はしない) 9 HogeHoge Contoso Contoso
Class が必要 IContoso Class Class Interface
コードでの例(DIを利用) public class HogeHoge { private IContoso _contoso; public HogeHoge(IContoso
contoso) { _contoso = contoso; } ・ ・ ・ 10 コンストラクタでインスタンスを 外から受け取っている
【依存性の注入】の個人的理解 11 依存性 →外側から持ってくる必要のあるインスタンス(オブジェクト) 注入 →クラスの中で生成するのではなく、引数として受け取る
Before After 12 Without DI With DI App obj2 obj3
obj4 App obj1 obj2 obj3 obj4 obj1 部品は固定 部品をカスタマイズできる
.NET Core におけるDI .NET Coreでは標準でDIをサポート 13 https://docs.microsoft.com/ja-jp/aspnet/core/fundamentals/dependency-injection?view=aspnetcore-3.0
Blazorでも使われています 14 https://docs.microsoft.com/ja-jp/aspnet/core/blazor/dependency-injection?view=aspnetcore-3.0
まとめ ・クラスの結合が強いと変更に弱くなってしまう →そこでDI! ・DIではオブジェクトを引数として受け取る ・DIのメリット ・カスタマイズがしやすい ・単体テストがしやすい 15
ご清聴ありがとうございました 16