Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Injecting a service into an entity

I have an entity called Container which depends on a service, DeviceService.

I currently inject it using an Entity Listener on postLoad. However this is not being injected when just creating the plain object new Container().

Should I create a ContainerFactory where I inject the service into the new object, along with the current listener, or do a smarter way exist in Symfony?

like image 609
Patrick Reck Avatar asked Oct 26 '25 10:10

Patrick Reck


1 Answers

You can use Doctrine events. See : https://symfonycasts.com/screencast/api-platform-extending/post-load-listener

like image 73
francoisV Avatar answered Oct 29 '25 08:10

francoisV



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!