AD0-E724 · Question #33
A developer needs to programmatically create a URL rewrite for a custom entity page. Which service contract (repository) should be used to save the 'UrlRewrite' object?
The correct answer is C. 'Magento\UrlRewrite\Api\UrlRewriteRepositoryInterface'. Magento\UrlRewrite\Api\UrlRewriteRepositoryInterface is correct because Magento's service contract pattern dictates that you always depend on interfaces, not concrete implementations - this ensures your code is decoupled, testable, and upgrade-safe. Option A (UrlRewriteSavingInte
Question
A developer needs to programmatically create a URL rewrite for a custom entity page. Which service contract (repository) should be used to save the 'UrlRewrite' object?
Options
- A'Magento\UrlRewrite\Api\UrlRewriteSavingInterface'
- B'Magento\UrlRewrite\Model\UrlRewriteRepository'
- C'Magento\UrlRewrite\Api\UrlRewriteRepositoryInterface'
- D'Magento\UrlRewrite\Model\ResourceModel\UrlRewrite'
How the community answered
(41 responses)- A12% (5)
- B7% (3)
- C78% (32)
- D2% (1)
Explanation
Magento\UrlRewrite\Api\UrlRewriteRepositoryInterface is correct because Magento's service contract pattern dictates that you always depend on interfaces, not concrete implementations - this ensures your code is decoupled, testable, and upgrade-safe. Option A (UrlRewriteSavingInterface) does not exist in Magento's codebase, making it a fabricated distractor. Option B (UrlRewriteRepository) is the concrete class that implements the interface, but coding against a concrete model violates the service contract principle and tightly couples your code to the implementation. Option D (ResourceModel\UrlRewrite) is a lower-level persistence layer class, not a repository service contract, and should never be used directly in custom business logic.
Memory tip: In Magento, always reach for the *Interface in the Api\ namespace - if you see a class without Interface in its name or outside Api\, it's almost certainly the wrong choice for a service contract question.
Topics
Community Discussion
No community discussion yet for this question.