Preference a DTO interface to a model in Magento
Set a Magento 2 DTO interface preference in etc/di.xml to inject PostInterface as the Post model.
Lesson Content
While we created a DTO object, and then implemented it into our model, we still need to set this model up as a preference for this interface. If someone wishes to reference this PostInterface with dependency injection, Magento won’t yet know which class to substitute in for this interface.
Class preferences are defined in an etc/di.xmlfile, so let’s go ahead and created this. Then, we will define the root config node which uses the noNamespaceSchemaLocation of ObjectManager’s config.xsd.
<?xml version="1.0"?>
<config xmlns:xsi="http://w...
Join the discussion!
Comments
Want to comment on this lesson?
Enroll in this course to leave comments.