I've used DI preferences to set an interface to use a class in my own module e.g.
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <preference for="Magento\CatalogInventory\Api\StockManagementInterface" type="MySpace\MyModule\Model\StockManagement"/> </config>
However, there is also a DI preference for this interface in the original core module.
In some cases this works, and others (such as in this case for Magento\CatalogInventory\Api\StockManagementInterface), it does not - it still uses the original.
What determines which class wins out? If it cannot be determined, how is this a reliable way to do a full class rewrite in the many many cases where Magento 2 has made it impractical to use a plugin or observer?
[Note that I "solved" the above issue by setting a preference for the class Magento\CatalogInventory\Model\StockManagement instead, but this does not allow for direct use of that class such as for composition]