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
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
270
Greengrassを使ったIoTのアーキテクチャ
hisami
0
190
ECS Execを使ってFargateにログインしてみた
hisami
1
420
Other Decks in Technology
See All in Technology
おい、エージェントを使って終わらせろ
nwiizo
0
190
データ界隈LT祭 第1回LT登壇
taromatsui_cccmkhd
1
1.3k
積み重なった技術負債への挑戦 〜初手としての全社ゴト化〜
techtekt
PRO
0
720
Multica × 長期記憶:40個のミニプロジェクト管理
eiei114
1
280
2026-09-11 【Snowflake World Tour Tokyo 2026】Snowflakeを起点に、AI Agentが自律稼働し続ける未来へ / Driving AI Agents with Snowflake
civitaspo
0
390
SREは、MCPとAutopilotをこう使え!
kazumax55
2
730
DEFCON_CHV_CTF_Write-up.pdf
bata_24
0
150
幾何アルゴリズムで なめらかなピン操作を / iOSDC Japan 2026 / smoothpin
kazumanagano
0
340
データ_AIの事業の勝敗をわけるもの
nek0128
0
240
生成AIエージェントを用いた、 手動テスト手順書から自動テストへの 変換手法の検討
magicpod
0
140
AI時代、データエンジニアが一番おもろい
genshun9
0
540
10分で知る最近のOmarchy
komagata
0
300
Featured
See All Featured
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
980
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
590
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
500
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Are puppies a ranking factor?
jonoalderson
2
3.9k
Typedesign – Prime Four
hannesfritz
42
3.2k
Discover your Explorer Soul
emna__ayadi
2
1.3k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.3k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.2k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
390
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
The Mindset for Success: Future Career Progression
greggifford
PRO
0
490
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のメリット→より簡単に自由にテスト書ける