Using Object Manager in Magento code is still a pattern I see way too often in custom Magento modules.
Let's fix it.
❌ BAD:
```
$productRepository = \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
$product = $productRepository->get('my-sku');
```
✅ GOOD:
```
public function __construct(
private ProductRepositoryInterface $productRepository
) {}
public function getProduct(string
$sku): ProductInterface
{
return
$this->productRepository->get($sku);
}
```
// WHY DOES THIS MATTER?
Using Object Manager directly breaks dependency injection:
- makes your code harder to debug
- violates Magento's coding standards
- doesn't create explicit dependencies in classes
Injecting deps within the constructor keeps your dependencies clear and your code maintainable.
The only time you should touch Object Manager? In factories, proxies, or backwards compatibility - and even then, think twice.
What other Magento anti-patterns drive you crazy?