Skip to content

Commit c2e3bf7

Browse files
Named *autowiring* alises
1 parent 71cb687 commit c2e3bf7

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

service_container/autowiring.rst

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -363,19 +363,18 @@ If you register this as a service, you now have *two* services that implement th
363363
which one to use. Remember, autowiring isn't magic; it looks for a service
364364
whose id matches the type-hint. So you need to choose one by creating an alias
365365
from the type to the correct service id (see :ref:`autowiring-interface-alias`).
366-
Additionally, you can define several named aliases if you want to use
366+
Additionally, you can define several named autowiring aliases if you want to use
367367
one implementation in some cases, and another implementation in some
368368
other cases.
369369

370-
371370
For instance, you may want to use by default the ``Rot13Transformer``
372371
implementation by default when the ``TransformerInterface`` interface is
373372
type hinted, but use the ``UppercaseTransformer`` implementation in some
374373
specific cases. To do so, you can create a normal alias from the
375374
``TransformerInterface`` interface to ``Rot13Transformer``, and then
376-
create a *named alias* from a special string containing the interface
377-
followed by a variable name matching the one you use when doing the
378-
injection::
375+
create a *named autowiring alias* from a special string containing the
376+
interface followed by a variable name matching the one you use when doing
377+
the injection::
379378

380379
namespace App\Service;
381380

@@ -423,9 +422,8 @@ injection::
423422
# the Rot13Transformer will be passed as the $transformer argument
424423
autowire: true
425424
426-
# If you wanted to choose the non-default service and
427-
# do not want to use a named alias, wire it manually
428-
# arguments:
425+
# If you wanted to choose the non-default service and do not
426+
# want to use a named autowiring alias, wire it manually:
429427
# $transformer: '@App\Util\UppercaseTransformer'
430428
# ...
431429
@@ -484,7 +482,7 @@ under the arguments key.
484482

485483
.. versionadded:: 4.2
486484

487-
Named aliases have been introduced in Symfony 4.2.
485+
Named autowiring aliases have been introduced in Symfony 4.2.
488486

489487
Fixing Non-Autowireable Arguments
490488
---------------------------------

0 commit comments

Comments
 (0)