Magento 1 Class Rewrite in Magento 2 with Dependency Injection System

Di configuration was moved to di.xml files, and format was modified. Now preferences look like this (di.xml):

<config>
    <preference for="{Interface_Or_Class_Name}" type="{Preferred_Class_Name}" />
</config>

You are correct, class rewrites were entirely eliminated and replaced with DI. The following notes are from the section on Application Framework changes:

Magento 1.x — Node: /global//{sub-path which corresponds to factory name + "rewrite" literal}

<global>
...
    <models>
        <core>
            <rewrite>
                <url>My_Module_Model_Url</url>
            </rewrite>
        </core>
    </models>
...
</global>

Magento 2.x — Node: /global/di/aliases

<global>
...
    <di>
        <aliases>
            <Mage_Core_Model_Url>My_Module_Model_Url</Mage_Core_Model_Url>
        </aliases>
    </di>
...
</global>

I haven't tried utilizing this in a module running in Magento 2.0, but it appears that you basically define an alias for the class name instead of using the complicated hierarchy of xml for per-module rewrites.


Working from the inside out, I was able to get a rewrite working with the following

<global>    
    <di>    
        <preferences>
            <Mage_Catalog_Model_Product>Packagename_Modulename_Model_Product</Mage_Catalog_Model_Product>
        </preferences> 
    </di>
</global>

However, there's a lot more systems code in the dependency injection implementation, so it's not clear if the above will work in the final released version of Magento 2.