@@ -549,13 +549,35 @@ Another option is to use the ``#[Target]`` attribute. By adding this attribute
549
549
to the argument you want to autowire, you can specify which service to inject by
550
550
passing the name of the argument used in the named alias. This way, you can have
551
551
multiple services implementing the same interface and keep the argument name
552
- separate from any implementation name (like shown in the example above).
552
+ separate from any implementation name (like shown in the example above). In addition,
553
+ you'll get an exception in case you make any typo in the target name.
553
554
554
555
.. warning ::
555
556
556
557
The ``#[Target] `` attribute only accepts the name of the argument used in the
557
558
named alias; it **does not ** accept service ids or service aliases.
558
559
560
+ You can get a list of named autowiring aliases by running the ``debug:autowiring `` command::
561
+
562
+ .. code-block :: terminal
563
+
564
+ $ php bin/console debug:autowiring LoggerInterface
565
+
566
+ Autowirable Types
567
+ =================
568
+
569
+ The following classes & interfaces can be used as type-hints when autowiring:
570
+ (only showing classes/interfaces matching LoggerInterface)
571
+
572
+ Describes a logger instance.
573
+ Psr\Log\LoggerInterface - alias:monolog.logger
574
+ Psr\Log\LoggerInterface $assetMapperLogger - target:asset_mapperLogger - alias:monolog.logger.asset_mapper
575
+ Psr\Log\LoggerInterface $cacheLogger - alias:monolog.logger.cache
576
+ Psr\Log\LoggerInterface $httpClientLogger - target:http_clientLogger - alias:monolog.logger.http_client
577
+ Psr\Log\LoggerInterface $mailerLogger - alias:monolog.logger.mailer
578
+
579
+ [...]
580
+
559
581
Suppose you want to inject the ``App\Util\UppercaseTransformer `` service. You would use
560
582
the ``#[Target] `` attribute by passing the name of the ``$shoutyTransformer `` argument::
561
583
0 commit comments