Magento 2 – Circular Dependency: Customer Model Session and URL

dependencyerrormagento2

Magento2 shows this error:

Circular dependency: Magento\Customer\Model\Session depends on Magento\Customer\Model\Url and vice versa.

I have cleared var/cache and var/generation directory. But it doesn't work.
Does anyone know how to solve it?

Best Answer

This should not happen.
Make sure you have this in the di.xml of the customer module

<type name="Magento\Customer\Model\Session">
    <arguments>
        <argument name="configShare" xsi:type="object">Magento\Customer\Model\Config\Share\Proxy</argument>
        <argument name="customerUrl" xsi:type="object">Magento\Customer\Model\Url\Proxy</argument>
        <argument name="customerResource" xsi:type="object">Magento\Customer\Model\ResourceModel\Customer\Proxy</argument>
        <argument name="storage" xsi:type="object">Magento\Customer\Model\Session\Storage</argument>
        <argument name="customerRepository" xsi:type="object">Magento\Customer\Api\CustomerRepositoryInterface\Proxy</argument>
    </arguments>
</type>

this means that the session model would use as dependency Magento\Customer\Model\Url\Proxy instead of Magento\Customer\Model\Url.

Clear the var/generation folder in case something was wrongly generated.

Related Topic