alexdebril / rss-atom-bundle

RSS and Atom Bundle for Symfony
MIT License
139 stars 49 forks source link

Documentation for Symfony 4 #176

Closed tacman closed 6 years ago

tacman commented 6 years ago

This is probably easy, but I'm having a hard time figuring out how to use the FeedIo service properly in Symfony 4, where the container is not available.

I think it's just a matter of properly setting up the dependency injection in the class that needs it, but it's failing when I do this:

    public function __construct(FeedInterface $feedIo) {
       $this->feedIo = $feedIo;
    } 

the error is

  [Symfony\Component\DependencyInjection\Exception\RuntimeException]                                                                                
  Cannot autowire service "App\Services\HeadlineService": argument "$feedIo" of method "__construct()" references interface "FeedIo\FeedInterface"  
   but no such service exists. Did you create a class that implements this interface? 

Maybe I need to set up something in services.yaml? Can you please provide an example.

Thanks!

tacman commented 6 years ago

I added this to services.yaml:

    FeedIo\FeedIo:
        public: true
        alias: feedio

And changed the typehint in the constructor to FeedIo, and it seems to work now.

alexdebril commented 6 years ago

Thank you for your feedback, I'll add it to the documentation

alexdebril commented 6 years ago

In fact, it's a bug.

FeedIo\FeedIo should be configured to allow autowiring in your application