Select the right service for dependency injection #42494
-
I'm converting some 3.4 code to run under 4.0. I have this line in a Controller:
In 3.4 it fetches a
If I try to use dependency injection in 4.0 with
How do I use dependency injection to get the right object? These are the relevant lines:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
I don't know if there may be something SwiftMailer specific, but you could use a In your services:
_defaults:
bind:
$swiftMailerTransport: '@swiftmailer.transport.real' Now in your controller you can: public function (Swift_Transport_EsmtpTransport $swiftMailerTransport)
{
// ... |
Beta Was this translation helpful? Give feedback.
I don't know if there may be something SwiftMailer specific, but you could use a
bind
: it allows you to bind a specific service instance to a parameter name. Something quite useful when upgrading from legacy!In your
services.yaml
, do:Now in your controller you can: