News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Matthias Noback:
Inject a repository instead of an entity manager
May 19, 2014 @ 11:04:30

Matthias Noback has made a recommendation in his latest post about using a repository rather than an entity manager in your classes to inject dependencies.

It appears that I didn't make myself clear while writing about entity managers and manager registries yesterday. People were quick to reply that instead you should inject entity repositories. However, I wasn't talking about entity repositories here. I was talking about classes that get an EntityManager injected because they want to call persist() or flush(). The point of my previous post was that in those cases you should inject the manager registry, because you don't know beforehand which entity manager manages the entities you are trying to persist. By injecting a manager registry you also make your code useful in contexts where another Doctrine persistence library is used.

He suggests that more classes actually need a repository and not an entity manager to work with necessary objects. He also points out how the use of an entity manager can sometimes violate the Law of Demeter. He includes some code showing a refactoring away from an entity manager and towards a repository. He also has an example of a custom repository class based on the domain logic object types. In addition he talks about repository interfaces, resetting closed entity managers and "criteria" objects.

0 comments voice your opinion now!
repository entity manager doctrine refactor example

Link: http://php-and-symfony.matthiasnoback.nl/2014/05/inject-a-repository-instead-of-an-entity-manager/

blog comments powered by Disqus

Similar Posts

Mike Potter's Blog: AMFPHP 1.9 Examples from Renaun Erickson

NetTuts.com: Refactoring Legacy Code: Part 8 - Inverting Dependencies for a Clean Architecture

Chris Hartjes' Blog: Simple User Registration in CakePHP 1.2

Cormac' PHP Blog: Practical example php implementation of the Observer pattern

PHP Thinktank Blog: AJAX with Elazar (IRC Talk Series)


Community Events





Don't see your event here?
Let us know!


bugfix language zendserver podcast series interview conference release api framework symfony threedevsandamaybe community development tips list introduction laravel code deployment

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework