Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Dependency Injection はじめの一歩 / 20191024 C#Tokyo
Search
Taka
October 24, 2019
Programming
900
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Dependency Injection はじめの一歩 / 20191024 C#Tokyo
2019/10/24
.NET Core 3.0 リリース記念 C# Tokyo 2019/10 発表資料
Taka
October 24, 2019
Transcript
16 slides
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
More Decks by Taka
See All by Taka
フロントエンド初心者が Blazorを使ってみた / 20220428 C#Tokyo
takahiro901
0
510
HoloLens 2なしでも MRを楽しむ!
takahiro901
0
1.2k
BlazorのPWAを使ってみた / Tried using PWA
takahiro901
0
1.5k
C#勉強法: コンソールでアプリを作ろう / 20190910 C# Tokyo
takahiro901
0
880
Xamarin.Formsで自分用の家計簿アプリを作ってみた / 20190831 JXUG
takahiro901
0
1k
プログラミング初心者が Xamarin.Formsやってみた / 20180523 JXUG
takahiro901
0
460
Other Decks in Programming
See All in Programming
高速開発を止めずに 性能を上げる Flyleのシステム刷新と改善の歴史
azihsoyn
0
110
Canvas 2D Context Next
petamoriken
0
190
Materialが消えた日 〜真っ白なFlutterキャンバスにRenderObjectで絵を描く〜
umigishiaoi
0
170
Secure Your Coding Agent Like It’s Malware (v1.5) 🇬🇧 @Code.talks 2026
richargh
0
210
Getting Started with Vibe Coding
miccheng
0
250
Claude Codeのおかげでやりたいことがやれるようになったんだよォー!
sms_tech
0
190
JavaScriptはシングルバイナリの夢を見るか / Does JavaScript Dream of a Single Binary?
ssssota
0
360
仕様駆動開発入門 (何を作るかを先に決めて渡す) | 目指せ Kiro マスター 05
inariku
PRO
3
230
動画プレイヤーはなぜカクつくのか 〜Flutterのレンダリングとネイティブの境界を解剖する〜
naruogram
0
340
protojson における文字化けの扱い
kazuki1023
0
460
AI駆動TDD ― 2026年10月版
hrmstrsmgs
0
110
エージェントの管理もエージェントに – herdr-core と自作バックログで作る司令塔 –
nearme_tech
PRO
2
150
Featured
See All Featured
Optimizing for Happiness
mojombo
378
72k
Paper Plane
katiecoart
PRO
6
55k
My Coaching Mixtape
mlcsv
0
400
Design in an AI World
tapps
1
400
Chasing Engaging Ingredients in Design
codingconduct
0
410
Skip the Path - Find Your Career Trail
mkilby
1
300
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.5k
First, design no harm
axbom
PRO
2
1.4k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.8k
Un-Boring Meetings
codingconduct
0
510
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.8k
From π to Pie charts
rasagy
1
460