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
Filip Procházka
January 27, 2014
Technology
0
43
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
130
Value objects in PHP
fprochazka
1
160
Jak psát testy na REST API
fprochazka
0
68
V gitu se nic neztratí
fprochazka
0
340
Co se PHP programátor může naučit od Javy?
fprochazka
1
84
4 roky remote
fprochazka
1
77
Před čím tě Nette ani Symfony neochrání
fprochazka
0
150
Nejlepší cache je žádná cache
fprochazka
0
110
Doctrine: co dělat, když entity nestačí
fprochazka
0
48
Other Decks in Technology
See All in Technology
rootful・rootless・privilegedコンテナの違い/rootful_rootless_privileged_container_difference
moz_sec_
0
110
生成AIによるテスト設計支援プロセスの構築とプロセス内のボトルネック解消の取り組み / 20241220 Suguru Ishii
shift_evolve
0
180
実践! ソフトウェアエンジニアリングの価値の計測 ── Effort、Output、Outcome、Impact
nomuson
0
1.4k
OPENLOGI Company Profile for engineer
hr01
1
17k
pg_bigmをRustで実装する(第50回PostgreSQLアンカンファレンス@オンライン 発表資料)
shinyakato_
0
150
SpiderPlus & Co. エンジニア向け会社紹介資料
spiderplus_cb
0
460
サイバー攻撃を想定したセキュリティガイドライン 策定とASM及びCNAPPの活用方法
syoshie
3
1.7k
12 Days of OpenAIから読み解く、生成AI 2025年のトレンド
shunsukeono_am
0
1k
Accessibility Inspectorを活用した アプリのアクセシビリティ向上方法
hinakko
0
110
.NET 最新アップデート ~ AI とクラウド時代のアプリモダナイゼーション
chack411
0
150
NOT VALIDな検査制約 / check constraint that is not valid
yahonda
1
110
Zero Data Loss Autonomous Recovery Service サービス概要
oracle4engineer
PRO
1
5k
Featured
See All Featured
Docker and Python
trallard
43
3.2k
Six Lessons from altMBA
skipperchong
27
3.5k
Become a Pro
speakerdeck
PRO
26
5.1k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
Speed Design
sergeychernyshev
25
720
Faster Mobile Websites
deanohume
305
30k
We Have a Design System, Now What?
morganepeng
51
7.3k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
33
2.7k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
230
52k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Visualization
eitanlees
146
15k
The Power of CSS Pseudo Elements
geoffreycrofte
74
5.4k
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?