Table of Contents
- What is the Service Locator pattern?
- The role of the ObjectManager in Magento 2
- Why ObjectManager::getInstance() is an anti-pattern
- SOLID principles and how ObjectManager violates them
- Legitimate exceptions: when the ObjectManager is allowed
- The right way: Constructor Injection in PHP 8.4
- Factories instead of ObjectManager::create()
- Mocking and refactoring the ObjectManager in unit tests
- Recognizing and fixing typical code smells
- Summary
- FAQ
What is the Service Locator pattern?
The Service Locator pattern is a design pattern for resolving dependencies