Skip to content

Commit addf4bd

Browse files
committed
minor #18896 Clarify differences between attributes. (miqrogroove)
This PR was squashed before being merged into the 6.3 branch. Discussion ---------- Clarify differences between attributes. Fixes #18895 AutowireServiceClosure and AutowireCallable behave differently and needed a bit more explanation. <!-- If your pull request fixes a BUG, use the oldest maintained branch that contains the bug (see https://symfony.com/releases for the list of maintained branches). If your pull request documents a NEW FEATURE, use the same Symfony branch where the feature was introduced (and `6.x` for features of unreleased versions). --> Commits ------- 02188fb Clarify differences between attributes.
2 parents 12029a0 + 02188fb commit addf4bd

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)