Date: June 1, 2015 (given the changing nature of Magento 2)

In Magento 2, you can configure a "virtual type" in a module's di.xml configuration file. These virtual types allow you to change the arguments of a specific injected dependency.

In the core Magento 2 code, there appears to be two naming conventions for virtual types. In the first, a virtual type has a name that appears identical to a real PHP class name.

#File: app/code/Magento/CatalogRule/etc/di.xml
<virtualType name="Magento\Catalog\Pricing\Price\Pool" ...

in the second, a simple, backslash-less string is used

#File: app/code/Magento/CatalogSearch/etc/di.xml
<virtualType name="advancedSearchFilterList" ...

Is there any practical difference to the above two naming conventions? i.e. does the name you chose for a virtualType have any impact on its behavior, or is it just a globally unique string that identifies the type so you can use it later on.


The name of virtual type is just a globally unique string. There is no difference in behavior for differently named virtual types. We just don't have strong naming convention for virtual types. I personally prefer second approach because it makes it obvious that this is virtual type, not a real class.

  • 2
    This being a 1.5 yo post, is the conventions still that there is no convention? I should use what ever I want for virtual types, but you still encourage me to use the second approach? Or do you have a new standard by now?
    – Marius
    Oct 14 '16 at 7:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.