diff --git a/messenger/working-with-doctrine.rst b/messenger/working-with-doctrine.rst index 87e4bb73311..1c2fb605e8a 100644 --- a/messenger/working-with-doctrine.rst +++ b/messenger/working-with-doctrine.rst @@ -9,25 +9,6 @@ writes in a single Doctrine transaction. This make sure that if one of your data query fails, then all queries are rolled back and give you a change to handle the exception knowing that your database was not changed by your message handler. -To make sure your message bus wraps the handler in one transaction you must first -register the middleware as a service. - -.. configuration-block:: - - .. code-block:: yaml - - # config/services.yaml - services: - app.messenger.middleware_factory.transaction: - class: Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddlewareFactory - arguments: ['@doctrine'] - - app.doctrine_transaction_middleware: - class: Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddleware - factory: ['@app.messenger.middleware_factory.transaction', 'createMiddleware'] - abstract: true - arguments: ['default'] - Next thing you need to do is to add the middleware to your bus configuration. .. configuration-block:: @@ -37,9 +18,47 @@ Next thing you need to do is to add the middleware to your bus configuration. # config/packages/messenger.yaml framework: # ... - default_bus: messenger.bus.command buses: messenger.bus.command: middleware: - - messenger.middleware.validation - - app.doctrine_transaction_middleware: ['default'] + - validation + - doctrine_transaction + + .. code-block:: xml + + + + + + + + + + + + + + + + .. code-block:: php + + // config/packages/messenger.php + $container->loadFromExtension('framework', [ + 'messenger' => [ + 'buses' => [ + 'messenger.bus.commands' => [ + 'middleware' => [ + 'validation', + 'doctrine_transaction', + ], + ], + ], + ], + ]); +