Symfony2: Routing to Controller as Service with Annotations

A very quick post as I couldn't find anything documenting this yet (I will submit this to the docs also). If you want to use the combination of annotations for routing and also make your controllers into services then you can by specifying the service id in the class route:


namespace ExampleBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

/** @Route("/example", service="example_bundle.controller.example_controller") */
class ExampleController

Whether you should make controllers services is a while different matter and I am going to stay away from that can of worms (at least for today).