Skip to content

Commit 02188fb

Browse files
miqrogroovejaviereguiluz
authored andcommitted
Clarify differences between attributes.
1 parent b038b1f commit 02188fb

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

service_container/autowiring.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,8 @@ Generate Closures With Autowiring
658658
---------------------------------
659659

660660
A **service closure** is an anonymous function that returns a service. This type
661-
of instanciation is handy when you are dealing with lazy-loading.
661+
of instanciation is handy when you are dealing with lazy-loading. It is also
662+
useful for non-shared service dependencies.
662663

663664
Automatically creating a closure encapsulating the service instanciation can be
664665
done with the
@@ -716,7 +717,9 @@ In this case, you can use the
716717
:class:`Symfony\Component\DependencyInjection\Attribute\\AutowireCallable` attribute
717718
to generate a closure with the same signature as a specific method of a service. When
718719
this closure is called, it will pass all its arguments to the underlying service
719-
function::
720+
function. If the closure needs to be called more than once, the service instance
721+
is reused for repeated calls. Unlike a service closure, this will not
722+
create extra instances of a non-shared service.
720723

721724
// src/Service/MessageGenerator.php
722725
namespace App\Service;
@@ -727,7 +730,7 @@ function::
727730
{
728731
public function __construct(
729732
#[AutowireCallable(service: 'third_party.remote_message_formatter', method: 'format')]
730-
\Closure $formatCallable
733+
private \Closure $formatCallable
731734
) {
732735
}
733736

0 commit comments

Comments
 (0)