28

From 2.1 Magento has introduced Magento/Framework/Model/EntityManager

I may be wrong here but from my understanding it is to replace Magento/Framework/Model/AbstractModel which was implementing the feature via inheritance and solve this via composition (FYI : https://en.m.wikipedia.org/wiki/Composition_over_inheritance )

You can get an example here in the core files: https://github.com/magento/magento2/blob/59671558ecdab652b40db2d1a7c63d5b1dea0a92/app/code/Magento/Cms/Model/ResourceModel/Block.php

Basically all the CRUD operations are explicitly declared in the class and deferred to the EntityManager class. Before 2.1, the parent method was called via inheritance.

So my questions are:

  • what are the benefits of the EntityManager over the pre 2.1 inheritance system?
  • is simply declaring the CRUD methods (like the example above) enough to start implementing it in a custom CRUD module or is there more?
Raphael at Digital Pianism
  • 70,385
  • 34
  • 188
  • 352
  • 1
    Not an answer - but I would hazard one of the benefits of using an EntityManager would be the ability for a possible injection of a Repository type system - where loading might happen in-memory rather than hitting the DB if the entity had already been pulled into memory, etc. – Navarr Jul 25 '16 at 17:04

1 Answers1

18

Currently, we do not recommend to use EntityManager for your entities as it's an unfinished feature and we plan to make configuration more declarative.

Ideas of EntityManager are:

  • allow persist Data Entity by the interface (no need to extends from abstract classes)
  • make persistent explicit extensible
  • modularity
Raphael at Digital Pianism
  • 70,385
  • 34
  • 188
  • 352
KAndy
  • 20,811
  • 3
  • 49
  • 59