Skip to content

[Lock] Replace LockInterface by LockFactory in DI #14427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions lock.rst
Original file line number Diff line number Diff line change
Expand Up @@ -159,22 +159,23 @@ this behavior by using the ``lock`` key like:
Locking a Resource
------------------

To lock the default resource, autowire the lock using
:class:`Symfony\\Component\\Lock\\LockInterface` (service id ``lock``)::
To lock the default resource, autowire the lock factory using
:class:`Symfony\\Component\\Lock\\LockFactory` (service id ``lock.factory``)::

// src/Controller/PdfController.php
namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Lock\LockInterface;
use Symfony\Component\Lock\LockFactory;

class PdfController extends AbstractController
{
/**
* @Route("/download/terms-of-use.pdf")
*/
public function downloadPdf(LockInterface $lock, MyPdfGeneratorService $pdf)
public function downloadPdf(LockFactory $factory, MyPdfGeneratorService $pdf)
{
$lock = $factory->createLock('pdf-creation');
$lock->acquire(true);

// heavy computation
Expand Down Expand Up @@ -273,18 +274,12 @@ provides :ref:`named lock <reference-lock-resources-name>`::
],
]);

Each name becomes a service where the service id suffixed by the name of the
lock (e.g. ``lock.invoice``). An autowiring alias is also created for each lock
using the camel case version of its name suffixed by ``Lock`` - e.g. ``invoice``
can be injected automatically by naming the argument ``$invoiceLock`` and
type-hinting it with :class:`Symfony\\Component\\Lock\\LockInterface`.

Symfony also provide a corresponding factory and store following the same rules
(e.g. ``invoice`` generates a ``lock.invoice.factory`` and
``lock.invoice.store``, both can be injected automatically by naming
respectively ``$invoiceLockFactory`` and ``$invoiceLockStore`` and type-hinted
with :class:`Symfony\\Component\\Lock\\LockFactory` and
:class:`Symfony\\Component\\Lock\\PersistingStoreInterface`)
Each name becomes a service where the service id is part of the name of the
lock (e.g. ``lock.invoice.factory``). An autowiring alias is also created for
each lock using the camel case version of its name suffixed by ``LockFactory``
- e.g. ``invoice`` can be injected automatically by naming the argument
``$invoiceLockFactory`` and type-hinting it with
:class:`Symfony\\Component\\Lock\\LockFactory`.

Blocking Store
--------------
Expand Down