-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] Add new "routing.annotated_controller" service tag #21282
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
Comments
You have my vote for sure! See #12915 |
Although the approach in #12915 was refused, this sounds more reasonable today now that Tobion's comment is resolved and regarding the direction symfony is taking for controllers and bundless apps 👍. |
I'd prefer keeping the trigger and app specific route config in But the concept of annotated controllers as a service sounds good 👍 |
I prefer to keep routes in the routing itself, using tags feels to magical and less conventional. Secondly, using Annotations will couple you to the Framework (again) where registering Controllers are service is to prevent that. To automatically register routes to a pool (for manual importing) you can have a look at https://github.com/rollerworks/RouteAutowiringBundle (and it would be great if this could be moved to the Symfony framework itself, and improved where possible 👍 ). |
This would be nothing more than aggregating the services and then reading the annotations during cache warmup. Instead of having to guess the service id for the class based on annotation, this is probably injected during container compilation. |
There is several use cases for controller as a service. One can be decoupling actions form the framework. Another unrelated usage is too enable autowiring on controllers, so you can inject services without defining them in a config file. The suggestion of @nicolas-grekas makes sense in the 2nd context. The goal is to make the framework easy to use for newcomers, not to decouple from the framework. A more experimented developper can easily switch to framework-agnostic actions later. I like the idea. |
This may fit quite well with what is proposed in #21289 I guess: App\Controller\:
autowire: true
psr4: ../Controller/ # equals the "resource" routing attribute
tags:
- { name: routing.annotated_controller } |
For those who didn't see it, my message on Slack about this:
So, for me, the gain is not big enough (compared to the complexity to implement it) when we're talking about using this in an app. It could be for third party bundles but I think we should first wait and try using flex and then see if it's still needed. |
As long as the routes from 3rd party bundles are opt-in and not opt-out * |
I spend the day talking and thinking about this one. The envisioned benefit (being able to wire routes from DI) will require a lot of code, for a discussed benefit: allowing bundle to inject routes may not be a good idea. The target DX-ness requires only one line in routing.xml also. |
Uh oh!
There was an error while loading. Please reload this page.
When one defines a controller as a service, it would be nice to be able to wire it with routing in a snap of a tag.
eg
Using this tag, the routes would be specified as annotations on the related class+methods (which means moving AnnotatedRouteControllerLoader to FrameworkBundle.
This would allow bundles to take control of the wiring of their routing configuration. This means that just by enabling a bundle, its routing config would be done. Of course, each bundle could provide config to change the prefix, disable/enable routes conditionally, etc.
I also think that this would mean one less file to look at for new comers (I mean routing.yml.)
If someone would like to give it a try, please do :)
The text was updated successfully, but these errors were encountered: