I want to rewrite activate function of AccountManagement.I don’t know how to proceed.

According to documentation

A public interface is a set of code that third-party developers can call, implement, or pluginize. Magento guarantees that this code will not change in subsequent releases without a major version change.

Public interfaces for a module reside in the Api folder for a module. For example, the public interfaces for the Customer module reside in the app/code/Magento/Customer/Api folder. Third-party developers should use only these interfaces. You can use other interfaces but Magento does not guarantee that other interface will not be modified or removed in subsequent releases.

1.I need to rewrite AccountManagementInterface or AccountManagement?

2.It is necessary to use di.xml?

3.following is correct?

<preference for="Magento\Customer\Api\AccountManagementInterface"
                type="Mynamespace\Mymodule\Model\AccountManagement" />

Thanks in Advance.

1 Answer 1


The <preference> element in a di.xml file is the right approach. What you are doing is saying "use my type whenever you see a reference to the interface name in the merged di.xml file". So can supply any class that implements that interface. You could write this class from scratch (implementing the interface), or you could inherit the class we provide and override the one method with a new implementation (the class we provide implements the interface already).

Another approach is using plugins - you can intercept calls to an existing method without replacing the whole class, if that is appropriate. The advantage of plugins is you can add a bit of functionality to existing code easily, and if 3 different modules want to add functionality that will work as well. In comparison, only the last element will win - there can be only one class at the end of the day.

So you need to decide which approach best fits what you are trying to achieve. Since you are trying to rewrite a single function, you might want to look into plugins instead of using the <preference> element.

  • if i dont want to use plugins & dont want to implement from scratch then what will be the scenario? then i need to follow like this? <preference for="Magento\Customer\Model\AccountManagement" type="Mynamespace\Mymodule\Model\AccountManagement" />
    – sivakumar
    Jan 5, 2015 at 6:35
  • Preference for can replace a class - it says "if you see a reference to this interface, this is the class to supply". So that is more like the complete replacement option. Your replacement class could inherit from an existing class.
    – Alan Kent
    Jan 10, 2015 at 10:18
  • There are still events if supported where you need them too
    – Alan Kent
    Jan 10, 2015 at 10:19
  • @AlanKent What happens if multiple modules have <preference> for the AccountManagement class ?
    – Tuong Le
    Sep 1, 2015 at 12:40
  • hello @AlanKent <preference for="Magento\Customer\Model\AccountManagement" type="Mynamespace\Mymodule\Model\AccountManagement" /> is giving me error on checkout page when i am enable paypal express can you suggest something? Nov 14, 2017 at 11:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.