[英]Symfony event listener service shared
我有事件偵聽器作為服務,聲明為:
#[Autoconfigure(shared: true)]
#[AutoconfigureTag(name: 'doctrine.event_listener', attributes: [
'event' => Events::preUpdate,
'entity' => User::class,
'method' => 'preUpdate',
])]
#[AutoconfigureTag(name: 'doctrine.event_listener', attributes: [
'event' => Events::postFlush,
'method' => 'postFlush',
])]
class Sender
不幸的是,symfony 為 preUpdate 和 postFlush 創建了另一個 object,所以我不能使用共享這個。
它出什么問題了?
謝謝。
您創建了兩個同名的別名,symfony 將選擇第一個。 我相信它應該是這樣的:
#[AutoconfigureTag(name: 'doctrine.event_listener.preUpdate', attributes: [
'entity' => User::class,
'method' => 'preUpdate',
])]
#[AutoconfigureTag(name: 'doctrine.event_listener.postFlush', attributes: [
'method' => 'postFlush',
])]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.