Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update documentation to show using DI #26

Open
tacman opened this issue May 2, 2019 · 2 comments
Open

Update documentation to show using DI #26

tacman opened this issue May 2, 2019 · 2 comments

Comments

@tacman
Copy link

tacman commented May 2, 2019

Can you add an example in the documentation showing how to call the service via Dependency Injection, that than through the container?

That's Symfony's best practice recommendations now.

Thanks.

@phtmgt
Copy link

phtmgt commented Nov 20, 2019

yay, + one. We need this for symfony 4.3+.

@phtmgt
Copy link

phtmgt commented Nov 20, 2019

Let me help here, feel free to add this to the documentation:

services.yaml:

MartinGeorgiev\SocialPost\Publisher: '@social_post'

In your Controller:

use MartinGeorgiev\SocialPost\Publisher as SocialPublisher;
use MartinGeorgiev\SocialPost\Message as SocialMessage;

...
public function myFunction (SocialPublisher $publisher) {
...

$post = new SocialMessage('post content here');
$publisher->publish($post);

...
}

Is you want to use it in a service, just pass SocialPublisher to the __construct method. Hope this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants