Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Dependency injection v Nette 2.1 prakticky
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Filip Procházka
January 27, 2014
Technology
0
49
Dependency injection v Nette 2.1 prakticky
Filip Procházka
January 27, 2014
Tweet
Share
More Decks by Filip Procházka
See All by Filip Procházka
Evolving architecture
fprochazka
0
230
Value objects in PHP
fprochazka
1
220
Jak psát testy na REST API
fprochazka
0
110
V gitu se nic neztratí
fprochazka
0
390
Co se PHP programátor může naučit od Javy?
fprochazka
1
130
4 roky remote
fprochazka
1
86
Před čím tě Nette ani Symfony neochrání
fprochazka
0
150
Nejlepší cache je žádná cache
fprochazka
0
130
Doctrine: co dělat, když entity nestačí
fprochazka
0
69
Other Decks in Technology
See All in Technology
Vitest Highlights in Angular
rainerhahnekamp
0
130
小さく始めるBCP ― 多プロダクト環境で始める最初の一歩
kekke_n
1
280
コスト削減から「セキュリティと利便性」を担うプラットフォームへ
sansantech
PRO
3
930
Tebiki Engineering Team Deck
tebiki
0
23k
Introduction to Sansan for Engineers / エンジニア向け会社紹介
sansan33
PRO
6
67k
GSIが複数キー対応したことで、俺達はいったい何が嬉しいのか?
smt7174
3
130
AI推進者の視点で見る、Bill OneのAI活用の今
sansantech
PRO
2
320
M&A 後の統合をどう進めるか ─ ナレッジワーク × Poetics が実践した組織とシステムの融合
kworkdev
PRO
1
300
AWS Devops Agent ~ 自動調査とSlack統合をやってみた! ~
kubomasataka
3
330
Amazon Bedrock AgentCore 認証・認可入門
hironobuiga
2
490
レガシー共有バッチ基盤への挑戦 - SREドリブンなリアーキテクチャリングの取り組み
tatsukoni
0
180
Amazon Bedrock AgentCore EvaluationsでAIエージェントを評価してみよう!
yuu551
0
210
Featured
See All Featured
Darren the Foodie - Storyboard
khoart
PRO
2
2.3k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
1.5k
Faster Mobile Websites
deanohume
310
31k
Amusing Abliteration
ianozsvald
0
92
A Soul's Torment
seathinner
5
2.2k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.6k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
100
The Cost Of JavaScript in 2023
addyosmani
55
9.5k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
270
Embracing the Ebb and Flow
colly
88
5k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
69
Transcript
Nette ❤ DI @ProchazkaFilip - @Damejidlo
Co si povíme? - rychle prolítneme teorii DI - jak
to funguje v Nette - jak napsat použitelné rozšíření
Teorie: typy injekce - konstruktor - setter - property -
magie
Konstruktor injection class Cart extends Nette\Object { private $entityManager; public
function __construct(EntityManager $em) { $this->entityManager = $em; } http://wbab.suffolk.lib.ny.us/wp-content/uploads/2013/12/medals.jpg
Setter injection class Cart extends Nette\Object { private $entityManager; public
function setEntityManager(EntityManager $em) { $this->entityManager = $em; } http://wbab.suffolk.lib.ny.us/wp-content/uploads/2013/12/medals.jpg
Property injection class Cart extends Nette\Object { /** @var EntityManager
*/ public $entityManager; http://wbab.suffolk.lib.ny.us/wp-content/uploads/2013/12/medals.jpg
Magic injection class Cart extends Nette\Object { /** @var EntityManager
*/ private $entityManager; http://www.wyatt-lorenz.com/images/biohazard_warnings.jpg
Teorie: slovníček - DI Container (composition root) - služby -
implementace / abstrakce
Praxe: konfigurace - služby - rozšíření
Registrace služby services: - Damejidlo\Cart()
Konfigurace rozšíření nette: latte: macros: - Assets\CssMacro
Bacha na zanoření parameters: services: nette:
Praxe: typy služeb - modely - presentery - komponenty
Modely - konstruktor (99.99%) - setter (když jsi v úzkých)
- property (ehm?)
Presentery - konstruktor (myslím že ne Time) - setter inject*()
(přihořívá) - property @inject (vítěz!) /** @var Damejidlo\Cart @inject */ public $cart;
Presentery services: productListPresenter: class: ShopModule\ProductsPresenter() setup: - $tempPath(%tempPath%) # nebo
- BlogModule\ArticlePresenter()
Komponenty - konstruktor (ano prosím!) - setter (meh?) - property
(bleh)
Komponenty v presenterech protected function createComponentForm() { return new OrderForm($entityManager???)
}
Ruční továrničky class OrderFormFactory { private $em; function __construct(EntityManager $em)
{ … } /** @return OrderForm */ public function create() { return new OrderForm($this->em); }
Generované továrničky interface IOrderFormFactory { /** @return OrderForm */ function
create(); }
Generované továrničky services: orderFormFactory: implement: IOrderFormFactory # nebo - {implement:
IOrderFormFactory}
Generované továrničky /** @var IOrderFormFactory @inject */ public $orderFormFactory; protected
function createComponentOrderForm() { $form = $this->orderFormFactory->create(); $form->onSuccess[] = ...; return $form }
Rozšíření class OrmExtension extends CompilerExtension { # vytvori služby public
function loadConfiguration() { } # upravuje své a jiné služby public function beforeCompile() { } # hackuje DI container public function afterCompile() { }
Dobré rozšíření - Composer - MUST HAVE - Jednoduchá registrace
- Convention over Configuration - validujte
Dotazy?