Magento di

From OrcaQubits/agentic-commerce-skills-plugins · View interactive version

Magento di is an AI agent skill from the GitHub repository OrcaQubits/agentic-commerce-skills-plugins. Configure Magento 2 dependency injection — di.xml, types, virtual types, preferences, argument replacement, and Object Manager. Use when wiring dependencies, creating class variations, or configuring module integrations.

How to use this skill

Skill file

Magento 2 Dependency Injection

Before writing code

Fetch live docs:

  1. Web-search site:developer.adobe.com commerce php development components dependency-injection for the DI guide
  2. Fetch https://developer.adobe.com/commerce/php/development/ and navigate to DI documentation
  3. Web-search site:developer.adobe.com commerce php development build di-xml for di.xml reference

Conceptual Architecture

How DI Works in Magento

Magento's Object Manager reads di.xml configurations and automatically injects dependencies into class constructors. You declare what you need; the framework provides it.

Constructor injection is the primary pattern — declare dependencies as constructor parameters with type hints.

di.xml Scope

di.xml files are area-scoped:

Types

Configure constructor arguments for a specific class:

Virtual Types

Create class variations without writing new PHP files:

Preferences

Map an interface to a concrete implementation:

Argument Types

| Type | Description |

|------|-------------|

| string | String value |

| boolean | true or false |

| number | Integer or float |

| const | PHP constant value |

| null | Null value |

| object | Another class instance (injected) |

| array | Array of mixed argument types |

| init_parameter | Value from Magento\Framework\App\DeploymentConfig |

Shared vs Non-Shared

Sensitive/Environment Config

init_parameter type reads from app/etc/env.php — use for environment-specific values that shouldn't be in di.xml.

Common Patterns

Best Practices

Fetch the DI documentation for exact XML schema, element attributes, and current best practices before configuring.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.