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

Define service container usage in controllers #9

Open
PauliusMacernis opened this issue Nov 6, 2019 · 0 comments
Open

Define service container usage in controllers #9

PauliusMacernis opened this issue Nov 6, 2019 · 0 comments
Labels
question Further information is requested rule Issues related to adding/removing/changing code standard rules

Comments

@PauliusMacernis
Copy link
Member

PauliusMacernis commented Nov 6, 2019

Service classes may be defined in two main ways inside of yaml files:

  • Namespace, e.g.: As/A/Namespace/To/The/ServiceClass
  • Service Id: as.a.name.of.any.choice.refering.to.the.service.class.in.yaml.file

Therefore it is quite easy to get rid of service container usage in the controller class by simply strong-typing arguments of constructor of a controller with the namespace. However, it is not that easy to get rid of service container if the service id is used instead.

From the very first observations I see that there are couple of ways to go and all of them have trade-offs:

  1. It is possible to inject service IDs to constructor of a controller but this would require to turn off autowiring for that particular bundle.
  2. It is possible to create another class that wraps all of such "service ids" and inject it into constructor of a controller via autowiring instead.
  3. It is possible to just:
    a) Do not use service container in constructor at all, use autowiring with constructor instead.
    b) If the first one (a) is not possible (e.g., pim_catalog.query.product_query_builder_factory_without_permission usage case) then skip using autowiring with constructor completely.
  4. ?

It seems that service ids are kind of leftover from the old times when autowiring was not present.
Read more on the entire topic here:
https://symfony.com/doc/3.4/controller/service.html

We need to define a way we do it.

@PauliusMacernis PauliusMacernis added question Further information is requested rule Issues related to adding/removing/changing code standard rules labels Nov 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested rule Issues related to adding/removing/changing code standard rules
Projects
None yet
Development

No branches or pull requests

1 participant