Skip to content

Clarify differences between attributes. #18896

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
Sep 20, 2023
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
9 changes: 6 additions & 3 deletions service_container/autowiring.rst
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,8 @@ Generate Closures With Autowiring
---------------------------------

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

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

// src/Service/MessageGenerator.php
namespace App\Service;
Expand All @@ -727,7 +730,7 @@ function::
{
public function __construct(
#[AutowireCallable(service: 'third_party.remote_message_formatter', method: 'format')]
\Closure $formatCallable
private \Closure $formatCallable
) {
}

Expand Down