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
簡易 DI コンテナを作って DI コンテナを知る
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
ryounasso
December 13, 2023
Programming
1.5k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
簡易 DI コンテナを作って DI コンテナを知る
簡易 DI コンテナを作ることで、DI コンテナの仕組みについて調べてみました。
ryounasso
December 13, 2023
More Decks by ryounasso
See All by ryounasso
明日から始めるリファクタリング
ryounasso
0
300
駆け足で Google から学ぶテスト設計の指針
ryounasso
0
260
React inside basics: learn from “build own react"
ryounasso
0
250
抽象データ型について学んだ
ryounasso
0
500
開発効率向上のためのリファクタリングの一歩目の選択肢 ~コード分割~ / JJUG CCC 2024 Fall
ryounasso
0
4.4k
Clean Architecture by TypeScript & NestJS
ryounasso
0
1.2k
Fast API を用いた Web API の開発
ryounasso
1
650
テストゼロの個人開発プロジェクトにテストを導入した話
ryounasso
0
520
TypeScript_コンパイラの内側に片足を入れる
ryounasso
3
1.1k
Other Decks in Programming
See All in Programming
Unity6 URPによる海底をテーマにしたVJシステムの解説 | Unity Shader 完全に理解した 勉強会
gam0022
0
350
Workers Cache を知る
syumai
0
350
[2026-09-26]空論ジェネリックプロセス~テスト資産とAIで紡ぐ、再現可能なパフォーマンスチューニングの話~
tosite
0
260
AI が書く Go コードの品質を劇的に向上させる Linter: “declscope”
mpyw
0
490
re:Inventに行く前に知っておきたい現地参加のノウハウ
nokomoro3
0
400
なぜCTOを降りてFDEを選んだのか?〜なぜプロダクト企業がFDEで顧客の現場に踏み込むのか〜
gonta
1
190
残高管理から台帳サービスへの進化
artoy
0
180
Jetpack Compose Mechanisms
skydoves
2
700
AI時代のコードレビューは人に向けるな、仕組みに向けろ
texmeijin
5
3.6k
C#の現在地 進化の歴史と、AI時代の.NET Everywhere
neuecc
5
5.1k
Domain-Driven Transformation
hschwentner
2
2.3k
contenteditable と日本語入力に向き合う
colorful12
0
190
Featured
See All Featured
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Building the Perfect Custom Keyboard
takai
2
900
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.8k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
720
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.9k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
31k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
sira's awesome portfolio website redesign presentation
elsirapls
0
450
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
1
450
30 Presentation Tips
portentint
PRO
1
430
Transcript
DI コンテナを作って DI コンテナを知る ryounasso
簡易版 DI を作ってみた結果の学びをお話しします 詳しいコードの説明等は省いています🙇
普段から DI 使ってるけど... Spring Boot で DI 使ってるけど、内側がどうなっているのか理解できておらず... 自作して理解してみよう!
DI とは DI (Dependency Injection, 依存性の注入) B C A B
は C に依存している A は B に依存している A の依存対象 この依存関係を外部から確立する
DI とは B C A 全体を把握するのは難しい... D E F
DI とは B C A 組み立てをやってくれる D E F DI
コンテナ クライアント A を使いたい A
そもそもなぜ DI ? Controellr Service Repository xxServiceImpl xxController xxRepository xxService
implements ビジネスロジックがデータアクセス層に依存
そもそもなぜ DI ? Controlelr Service Repository xxServiceImpl xxController xxRepository xxService
implements DI Container Container
大事なのがリフレクションとアノテーション リフレクション クラスなどのメタ情報を扱うことができる Java 標準 API 定義情報などを知ることができるようになる アノテーション ソースコードに注釈をつけるもの @Overried,
@Inject
リフレクション リフレクションを使って、クラスのメタ情報を扱うことで どんなクラスが来ても対応できるようにする フレームワーク側からすると、どんなクラスが来るかわからない
None
アノテーション インジェクトしたいフィールドにアノテーションをつけることで コンテナが認識して、インジェクションを行ってくれる DIContainer.register("bar", Bar.class) 的なことを毎回するのは手間
アノテーション
まとめ DI コンテナの中のざっくりとした処理が理解できた リフレクション・アノテーションの重要性 改めて DI とは何かも復習することができた
参考資料 - 作って理解するDIコンテナ https://nowokay.hatenablog.com/entry/20160406/1459918560 - 【やさしくない!? Java】 リフレクションの話 https://www.youtube.com/watch?v=LR0nSDRR0Ac&list=PL0BiA lg8j4Zu7Uu6Zdrm2dl8g8kU15Qie&index=2