Skip to content

Select the right service for dependency injection #42494

Answered by romaricdrigon
CJDennis asked this question in Q&A
Discussion options

You must be logged in to vote

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:

services:
    _defaults:
        bind:
            $swiftMailerTransport: '@swiftmailer.transport.real'

Now in your controller you can:

public function (Swift_Transport_EsmtpTransport $swiftMailerTransport)
{
    // ...

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@romaricdrigon
Comment options

@CJDennis
Comment options

@romaricdrigon
Comment options

@CJDennis
Comment options

@CJDennis
Comment options

Answer selected by CJDennis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants