magento-di

Configure Magento 2 dependency injection via di.xml files.

35|16|Updated Mar 4, 2026
One-click install
npx skills add https://github.com/OrcaQubits/agentic-commerce-claude-plugins --skill magento-di
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: magento-di
Source: https://github.com/OrcaQubits/agentic-commerce-claude-plugins/tree/main/magento2-commerce/skills/magento-di
Command: npx skills add https://github.com/OrcaQubits/agentic-commerce-claude-plugins --skill magento-di

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill simplifies the complex process of configuring Magento 2's dependency injection system, ensuring that your application's components are wired together correctly and efficiently.

Core Features & Use Cases

  • Dependency Configuration: Define and manage di.xml files for various Magento areas (global, frontend, adminhtml, webapi).
  • Component Wiring: Set up preferences, virtual types, and argument replacements to customize class behavior.
  • Use Case: When integrating a new third-party module, use this Skill to configure its services and ensure they correctly interact with Magento's core functionalities by mapping interfaces to specific implementations.

Quick Start

Use the magento-di skill to configure a preference for the interface Magento\Catalog\Api\ProductRepositoryInterface to use the class Vendor\Module\Model\ProductRepository.

Frequently Asked Questions about magento-di

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I configure Magento 2 dependency injection using di.xml?

Configure Magento 2 dependency injection by defining types, virtual types, preferences, and argument replacements within di.xml files. This ensures precise control over object instantiation and service location across Magento areas like global, frontend, and adminhtml.

What is a preference in Magento 2 dependency injection?

A preference in Magento 2 dependency injection maps a PHP interface to a specific implementation class within di.xml. This allows you to customize class behavior by directing the framework to instantiate your preferred class instead of the default core class.

How do I set up virtual types in Magento 2 di.xml files?

Set up virtual types in Magento 2 di.xml files to create customized class instances without extending original PHP classes. Virtual types allow you to define new arguments and inject specific dependencies dynamically for tailored component wiring.

Can I define area-specific dependency injection configurations in Magento 2?

Yes, you can define area-specific dependency injection configurations in Magento 2. By placing di.xml files in dedicated directories such as frontend, adminhtml, or webapi, you ensure object instantiation rules apply only within those specific application areas.

When do I need to replace arguments in a Magento 2 di.xml file?

Replace arguments in a Magento 2 di.xml file when you need to modify the injected dependencies of an existing class without altering its source code. This allows precise customization of component behavior during module integration.

What's the best way to integrate a third-party module with Magento core services?

Integrate a third-party module with Magento core services by configuring dependency injection within di.xml. Map interfaces to your module's implementations using preferences to ensure correct interaction and seamless service location within the Magento framework.