4

What is the difference between these two objects in magento2? (Factory and Repository) I have seen that they have almost the same methods. What proper use does one have?

1 Answer 1

10

Different between factory and repository

Factory definition:

Factories are service classes that instantiate non-injectable classes, that is, models that represent a database entity. They create a layer of abstraction between the ObjectManager and business code.

Definition of repository:

A repository object is responsible for reading and writing your object information to an object store

See more details at When Should We Use a Repository and Factory in Magento 2?

3
  • Then, a factory to create a new object and repository to read and write existing objects in database?
    – Miguel
    Commented Jun 2, 2017 at 6:41
  • yes, it have that privilege ..
    – Amit Bera
    Commented Jun 2, 2017 at 7:15
  • before yo could load an object using factory but now load method is deprecated
    – Miguel
    Commented Jun 2, 2017 at 7:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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