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
TypeScriptでDIしてみた
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Ryohei Hisamitsu
January 16, 2021
Technology
530
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
TypeScriptでDIしてみた
Ryohei Hisamitsu
January 16, 2021
More Decks by Ryohei Hisamitsu
See All by Ryohei Hisamitsu
re:Invent参加フィードバック会
hisami
0
110
GoのアプリをEKS(Fargate)にデプロイしてみた話
hisami
0
280
Greengrassを使ったIoTのアーキテクチャ
hisami
0
190
ECS Execを使ってFargateにログインしてみた
hisami
1
430
Other Decks in Technology
See All in Technology
go-sqletch
moznion
0
140
自作バイナリを動かす「入口」8選
puhitaku
2
1.3k
⾮構造化データを価値に変える AI エージェント基盤とその組織
ivry_presentationmaterials
0
150
Snapshot Testing in Practice: Predictable and Reliable SwiftUI Views
fespinoza
0
210
DWH の限界突破! AI エージェント向け爆速リアルタイムデータ基盤 ClickHouse
jozono
1
390
「事実」を「計測」して、「解釈」する 〜AWS Lambdaのメモリ最適解の見つけ方〜
maimyyym
0
140
【Data Engineering Summit2026_登壇資料】医療ビッグデータ×AIエージェントを支えるデータ基盤とハーネスエンジニアリング
jmdc_presentation
0
140
AIにシークレットを見せない、WSL2で安全な開発環境
yazm
0
130
事業成長とデータ活用を止めないためのマネジメントへ挑戦
hiracky16
0
330
How to Design Configuration for Rails Applications
willnet
0
210
Cognition AI Japan - ウェビナー2_テストQA_運用監視
cogakira
0
140
Datadog の学び方 - あるいは、オブザーバビリティを学ぶとは何か
mananyuki
1
560
Featured
See All Featured
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.5k
The Spectacular Lies of Maps
axbom
PRO
1
1.1k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6.1k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
260
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.8k
The SEO Collaboration Effect
kristinabergwall1
1
590
Optimizing for Happiness
mojombo
378
71k
Thoughts on Productivity
jonyablonski
76
5.4k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.6k
Designing Experiences People Love
moore
143
24k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
1
280
Transcript
で してみた NCDC株式会社 久光遼平
DI(Dependency Injection)とは? • 依存性(Dependency)の注入(Injection) • もう少しわかりやすく あるクラスが依存している要素をクラスの外側から注入すること ClassA { private
classB constructor( ClassBInterface classB ) { this.classB = classB; } } ClassA { private classB constructor() { this.classB = new ClassB(); } }
何が嬉しいの? • 単体テストがしやすくなる! class Service { private repository; constructor() {
this.repository = new Repository(); } find() { // ... this.repository.find(); return; } } よくあるテストしにくい例 テストしたいのはService層のロジック Repository(DB)のテストも含まれてしまう ・テスト失敗した時の切り分けが面倒 ・実行時間がかかる DI→テスト側からモックを注入できる!
実際のアプリではどうやって注入するの? • DIコンテナという便利な仕組みがある ◦ インスタンスの生成、注入を一括で行ってくれる
TypeScriptのDIライブラリ
②注入する側 ①注入される側 ③DIコンテナ 実装例 ④express
まとめ • DIすればテストしやすい作りにできる • DIの仕組みを作るにはInversifyJSを使えば楽 • あとはテストの時にモックを注入するだけ! • 追記:Jestのモック機能を使えば、DIしなくてもテストは書けそう ◦
DIのメリット→より簡単に自由にテスト書ける