Magento 2 Service Contract – What is It?

magento2service-contract

In Magento 2, is there a concrete example of something that's built using the Service Contract concept? I've seen this term thrown around a lot, but looking at Magento 2 as it exists now it's not clear to me if Service Contracts are more guiding principles, or if they actually tie back to specific implementations of things in Magento 2.

Best Answer

As I understand it all the interfaces defined in the Api folder are the Service Contracts. So anywhere the interface is used instead of the actual implementation of the class it uses the Service Contract.

An example would be this plugin implementation here https://github.com/magento/magento2/blob/2.3.2/app/code/Magento/GiftMessage/Model/Plugin/OrderGet.php#L78

It uses

protected function getOrderGiftMessage(\Magento\Sales\Api\Data\OrderInterface $order)

instead of \Magento\Sales\Model\Order

Related Topic