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
890
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
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
870
Xamarin.Formsで自分用の家計簿アプリを作ってみた / 20190831 JXUG
takahiro901
0
990
プログラミング初心者が Xamarin.Formsやってみた / 20180523 JXUG
takahiro901
0
460
Other Decks in Programming
See All in Programming
AWSに止められる覚悟してますか?
morizo_1984
2
490
iOS 27でニュースアプリはどう変わる!? 〜日経電子版の新機能対応と、開発事例から〜
lynnswap
7
13k
WebRTC映像をAirPlayに対応させる挑戦.pdf
monolithic_adam
0
330
Embedded Swiftで作る自作USBデバイス によるiOSデバイスの自動テスト / iOSDC Japan 2026 glassfiber
glassfiber
0
240
setup-vp GitLab対応の裏側
naokihaba
0
140
Security issues being discussed on Web Platforms
petamoriken
0
1.4k
難しいけど、読めた。- OSSの入口に立った話。
sts11142
0
130
動作中のプログラムの中身をリアルタイムに覗く / Realtime Debugger for CSharp with Roslyn
prota
1
1.7k
速習iPhone Duo対応
yuukiw00w
2
910
Ghostty + Neovimで作る 透明でカッコ良い開発環境
j341nono
0
150
Verilogで学ぶCPU自作入門.pdf
uyuki234
7
3.9k
半永久的に提供し続けられるプライベートクラウドを目指して ― 利用者の認知負荷を抑えるAPI抽象化とハードウェア世代交代の基盤設計
tomokon
0
370
Featured
See All Featured
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
2
2.9k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
490
WCS-LA-2024
lcolladotor
0
840
Statistics for Hackers
jakevdp
799
230k
GitHub's CSS Performance
jonrohan
1033
470k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
600
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
840
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.7k
Practical Orchestrator
shlominoach
192
12k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
1
610
The Cost Of JavaScript in 2023
addyosmani
55
10k
Building AI with AI
inesmontani
PRO
1
1.3k
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