orm icon indicating copy to clipboard operation
orm copied to clipboard

[PROPOSAL] Remove memory caching of entity listeners

Open zquintana opened this issue 7 years ago • 1 comments

In the current version of this package the EntityListenerResolver memory caches instances of resolved listeners. This overrides the current behavior of the Laravel container. For example if a develop defines a listener as a factory (bind in Laravel) then it's turned into a singleton via this resolver. This breaks the container definition and forces developers to treat listeners as singletons. Where performance is an issue a developer can still define the listener as a singleton in container via singleton method in the container. Which also means that these checks at https://github.com/laravel-doctrine/orm/blob/1.4/src/Resolvers/EntityListenerResolver.php#L51 are a duplication of what already happens in the make method of the container.

For these reasons my proposal is that the resolve method of the listener be simplified to not cache instances created by the containers make method. It should still check to see if there is an instance in instances property for listeners that have been registered via register method.

zquintana avatar Sep 18 '17 17:09 zquintana

Feel free to PR it

patrickbrouwers avatar Feb 27 '18 12:02 patrickbrouwers