Help us improve
Share bugs, ideas, or general feedback.
From magento2-commerce
Configures Magento 2 dependency injection via di.xml: types, virtual types, preferences, argument replacement, Object Manager. Use for wiring dependencies, class variations, module integrations.
npx claudepluginhub orcaqubits/agentic-commerce-skills-plugins --plugin magento2-commerceHow this skill is triggered — by the user, by Claude, or both
Slash command
/magento2-commerce:magento-diThis skill is limited to the following tools:
The summary Claude sees in its skill listing — used to decide when to auto-load this skill
**Fetch live docs**:
Guides creation of Magento 2 custom modules: registration, directory structure, models, resource models, collections, declarative schema, data/schema patches. For building modules or reviewing architecture.
Generates DI container configuration for PHP 8.4 projects following DDD and Clean Architecture. Supports Symfony, Laravel, PHP-DI; creates modules, service providers, YAML configs, compiler passes, unit tests.
Provides Drupal 10/11 service definitions, constructor injection, interfaces, and plugin factories. Use when creating services, registering dependencies, or service container patterns.
Share bugs, ideas, or general feedback.
Fetch live docs:
site:developer.adobe.com commerce php development components dependency-injection for the DI guidehttps://developer.adobe.com/commerce/php/development/ and navigate to DI documentationsite:developer.adobe.com commerce php development build di-xml for di.xml referenceMagento'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 files are area-scoped:
etc/di.xml — global (all areas)etc/frontend/di.xml — storefront onlyetc/adminhtml/di.xml — admin panel onlyetc/webapi_rest/di.xml — REST API onlyetc/webapi_soap/di.xml — SOAP API onlyConfigure constructor arguments for a specific class:
string, boolean, number, const, null, object, array, init_parameterCreate class variations without writing new PHP files:
type attribute value)Map an interface to a concrete implementation:
<preference for="InterfaceName" type="ConcreteClassName" />| 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="false" on a type to get a new instance each timeSomeClassFactory) always create new instancesinit_parameter type reads from app/etc/env.php — use for environment-specific values that shouldn't be in di.xml.
shared="false" sparingly — most dependencies should be sharedFetch the DI documentation for exact XML schema, element attributes, and current best practices before configuring.