Video Lesson: Preference a DTO interface to a model in Magento

Preference a DTO interface to a model in Magento

This is premium content

Only available to enrolled or University students.
Join today to unlock all lessons in this course.

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...

Premium content

Enroll to unlock the full content and all course materials.

Maggie

Hey, I'm Maggie! 👋

Ask me anything.

Want to chat with Maggie?

Enroll in this course for AI tutor access.

Comments

Join the discussion!

Comments

Want to comment on this lesson?

Enroll in this course to leave comments.