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
Dependency injection v Nette 2.1 prakticky
Search
Filip Procházka
January 27, 2014
Technology
55
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Dependency injection v Nette 2.1 prakticky
Filip Procházka
January 27, 2014
More Decks by Filip Procházka
See All by Filip Procházka
Evolving architecture
fprochazka
0
250
Value objects in PHP
fprochazka
1
240
Jak psát testy na REST API
fprochazka
0
130
V gitu se nic neztratí
fprochazka
0
420
Co se PHP programátor může naučit od Javy?
fprochazka
1
150
4 roky remote
fprochazka
1
91
Před čím tě Nette ani Symfony neochrání
fprochazka
0
160
Nejlepší cache je žádná cache
fprochazka
0
130
Doctrine: co dělat, když entity nestačí
fprochazka
0
86
Other Decks in Technology
See All in Technology
日経電子版を支えていく Kasane Design System/fec_fukuoka
nikkei_engineer_recruiting
0
620
2026_devsumi_ozono.pdf
o3
2
240
GoにおけるFFIのこれまでとこれから
goccy
5
2.3k
AIに丸投げしないトイル削減 / Eliminating Toil Without Leaving It All to AI
kohbis
4
1.1k
WAF 運用改善の承認サイクル/SRE_BizReach_MIXI_1
visional_engineering_and_design
2
420
Sigmaで作る業務アプリ
kazushiro_honma
0
110
スクラムで身についていた動き方を、XPで捉え直してみた
codmoninc
PRO
1
340
2026-09-10 【Snowflake World Tour Tokyo 2026】dbt Core と Snowflake で実現する多層的なデータガバナンス / Multi-Layered Data Governance Powered by dbt Core and Snowflake
civitaspo
0
310
アプリをもっと"iOSアプリっぽく"する小さな工夫 / Small Touches That Make Your App Feel More Like an iOS App
matsuji
1
330
Sigmaユーザーのための有用リソース一挙公開 & Sigmaで使えるMCP #sigma_ucj /useful-resources-for-sigma-computing-users-and-mcps-with-sigma
shinyaa31
0
180
2026-09-11 【Snowflake World Tour Tokyo 2026】Snowflakeを起点に、AI Agentが自律稼働し続ける未来へ / Driving AI Agents with Snowflake
civitaspo
0
290
Tab5をRubyで動くパソコンにする
kishima
2
280
Featured
See All Featured
Ethics towards AI in product and experience design
skipperchong
2
370
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
240
Raft: Consensus for Rubyists
vanstee
141
7.7k
The agentic SEO stack - context over prompts
schlessera
0
920
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
520
How to Think Like a Performance Engineer
csswizardry
28
2.8k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
240
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
370
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
320
What does AI have to do with Human Rights?
axbom
PRO
1
2.4k
BBQ
matthewcrist
89
10k
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?