Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[DependencyInjection] [LazyServices] Add#[Autoconfigure] attribute mention#17784

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Changes fromall 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
43 changes: 43 additions & 0 deletionsservice_container/lazy_services.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,6 +41,8 @@ In order to use the lazy service instantiation, you will need to install the

$ composer require symfony/proxy-manager-bridge

.. _lazy-services_configuration:

Configuration
-------------

Expand DownExpand Up@@ -101,6 +103,26 @@ To check if your proxy works you can check the interface of the received object:
over the ``lazy`` flag and directly instantiate the service as it would
normally do.

You can also configure your service's laziness thanks to the
:class:`Symfony\\Component\\DependencyInjection\\Attribute\\Autoconfigure` attribute.
The attribute has to be used like this::

namespace App\Twig;

use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
use Twig\Extension\ExtensionInterface;

#[Autoconfigure(lazy: true)]
class AppExtension implements ExtensionInterface
{
// ...
}

.. versionadded:: 5.4

The :class:`Symfony\\Component\\DependencyInjection\\Attribute\\Autoconfigure` attribute
was introduced in Symfony 5.4.

Interface Proxifying
--------------------

Expand DownExpand Up@@ -159,6 +181,27 @@ specific interfaces.
;
};

Just like in the :ref:`Configuration <lazy-services_configuration>` section, you can
use the :class:`Symfony\\Component\\DependencyInjection\\Attribute\\Autoconfigure`
attribute to configure the interface to proxify by passing its FQCN as the ``lazy``
parameter value::

namespace App\Twig;

use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
use Twig\Extension\ExtensionInterface;

#[Autoconfigure(lazy: ExtensionInterface::class)]
class AppExtension implements ExtensionInterface
{
// ...
}

.. versionadded:: 5.4

The :class:`Symfony\\Component\\DependencyInjection\\Attribute\\Autoconfigure` attribute
was introduced in Symfony 5.4.

The virtual `proxy`_ injected into other services will only implement the
specified interfaces and will not extend the original service class, allowing to
lazy load services using `final`_ classes. You can configure the proxy to
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp