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
260
Value objects in PHP
fprochazka
1
250
Jak psát testy na REST API
fprochazka
0
140
V gitu se nic neztratí
fprochazka
0
420
Co se PHP programátor může naučit od Javy?
fprochazka
1
160
4 roky remote
fprochazka
1
95
Před čím tě Nette ani Symfony neochrání
fprochazka
0
160
Nejlepší cache je žádná cache
fprochazka
0
140
Doctrine: co dělat, když entity nestačí
fprochazka
0
89
Other Decks in Technology
See All in Technology
これだけは抑えておきたい!後悔しない re:Invent の過ごし方 / AWS re:Invent 2026 prestudy
kinunori
2
590
視野はAIに、視座は人に / ai-for-breadth-humans-for-perspective
nkzn
5
2.4k
Autonomous AI Lakehouse - Live AI Hubから始めるセキュアなAIデータ活用 -
oracle4engineer
PRO
2
180
生き様としてのSRE
hokkai7go
0
140
AIコーディングエージェント開発_全体像
happysamurai294
0
130
外国人エンジニアがVueプロトタイプで仕様を合わせている話 / Vue Fes Japan 2026 LT
eluwing
0
310
Obsidian Vault Architectures
x5gtrn
PRO
0
210
AIエージェント時代、Kaggleにどう取り組むか
takanao
2
410
データマネジメント × 法務で作りあげる、 freeeの新しいデータガバナンスへの軌跡
freee
PRO
2
570
Agent 活用環境の構築・運用のための AWS サービスのご紹介/agentcore-for-building-and-operating-agents
ren8k
1
280
正解のない研修に放り出されて / Being thrown into a training program with no right answers
ohnoeight
1
170
[re:Invent2026事前勉強会(有志開催)]続きは、ラスベガスの廊下で / continue-in-the-vegas-hallway
sh_fk2
0
420
Featured
See All Featured
Ten Tips & Tricks for a 🌱 transition
stuffmc
1
270
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.4k
Test your architecture with Archunit
thirion
2
2.5k
The SEO Collaboration Effect
kristinabergwall1
1
610
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.9k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
370
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
590
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
1.1k
A Modern Web Designer's Workflow
chriscoyier
699
190k
How to make the Groovebox
asonas
2
2.5k
The Language of Interfaces
destraynor
162
27k
Evolving SEO for Evolving Search Engines
ryanjones
0
340
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?