I understand that the preferred way to work in between modules in Magento 2 is using the service contracts.
So if I want to load a product, I use the product repository:
$product = $productRepository->getById($id);
which is by contract returning an instance of Magento\Catalog\Api\Data\ProductInterface
.
But I could also use the old way instead, calling the domain layer directly:
$product = $productFactory->create()->load($id);
Is there any case where this would be necessary or useful?
The devdocs say (highlight added):
A module can directly call into another module. This tightly coupled solution is not recommended for most situations, but is sometimes unavoidable.
[...]
Your strategy for calling another module’s domain-layer code is highly dependent upon the unique configuration and needs of your system.
Source: http://devdocs.magento.com/guides/v2.0/architecture/archi_perspectives/domain_layer.html
And a comment on a related question stated:
using the Repository will give you a Product data model (
Api/Data/Product
), which is a Product model converted into a dumbed-down DTO. Something to consider, as they're quite different
But as far as I can see the objects are the same under normal conditions, just the return types per phpDoc differ (Magento\Catalog\Api\Data\ProductInterface
/ Magento\Catalog\Model\Product
)