Patrick Reck
Patrick Reck

Reputation: 339

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?

Upvotes: 4

Views: 18781

Answers (1)

francoisV
francoisV

Reputation: 89

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

Upvotes: 2

Related Questions