DI and passing of dependencies

Constructor, methods, or public variables? Every way of passing dependencies has its pitfalls – immutability, inheritance, boilerplate code. I break down why even constructor injection isn't without problems and what could help.

David Grudl
14 years ago

DI versus Service Locator

Service locator looks like a handy way of passing dependencies, but in reality it's an antipattern. I explain why it violates the principle of explicit dependencies, and show how to distinguish legitimate constructs from a real service locator.

David Grudl
14 years ago

DI versus Lazy loading

When do DI and lazy loading come into conflict, and why is the factory-based solution actually flawed? The right approach is an accessor that returns the dependency without presuming how it was created.

David Grudl
14 years ago

What is Dependency Injection?

Hidden dependencies make code unpredictable and confusing. Yet DI is a surprisingly simple technique – just stop hiding dependencies and start passing them explicitly. Through practical examples, I show why it's worth it and how to do it.

David Grudl
14 years ago

Nette\Utils\Html – coder's little helper

Generating HTML tags “on the fly” leads to messy and error-prone code. Nette\Utils\Html solves this with an intuitive object-oriented interface featuring a fluent API for working with elements, attributes, and their children.

David Grudl
20 years ago

You've reached the end.

newer posts older posts
Check our other projects
  • Web Framework component-based MVC
  • Latte the safest & intuitive templates
  • Tester enjoyable unit testing in PHP
  • Tracy debugging tool you will love ♥
  • Dependency Injection challenging container
  • Caching
  • Database layer for PHP
  • Forms greatly facilitates web forms
  • Mail sending emails
  • Neon readable file format
  • PHP Code Generator
  • Schema user data validation
  • Utils collection of useful utilities
  • …list of all packages
Help & Support
  • Forum
  • Discord Nette
  • Release Notes
  • Commits
Learn
  • Documentation
  • Blog
  • API
  • About Nette
Community
  • Partners and sponsors
  • GitHub
  • Componette
  • Hall of Fame
  • Showcase
  • Donate Now
Choose your language
  • English
  • Česky
Follow us
Nette Blog Twitter

Hosted on e-infrastructure CESNET. Thank you for your support CESNET association

© 2008, 2026 David Grudl. All rights reserved.   Terms of use ▲ up