Open bronze1man opened 11 years ago
Well, the main benefit of defining a controller as a service is using dependency injection in the controller class. If you inject the whole container in it, you are loosing this benefit (as you are injecting the whole world as a dependency)
I think using dependency injection in the controller class is just one benefit. I can reuse the code in controller thought container. Or I can injection this service into another service. Or I can add a tag on it,to listen on some stuff. Or I can create a route base on controller service name.
I even think controller should always be a service.
BTW: Injecting the whole world as a dependency is better then use the whole world with global function or variable.
Define container as a service with JMSDiExtraBundle
Here tbf.container_aware is an abstract service to inject container to container_aware.
benefit: 1.test_controller is a service ,I can get it from container,and use it. 2.test_controller is a controller , I can add some route on it, and response some http request. 3.test_controller is a service ,I can use JMSAopBundle.
a better way to define container as a service ?