-
Notifications
You must be signed in to change notification settings - Fork 44
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
Make Team permission handler service lazy #141
Conversation
This also allows to remove \Drupal::service() call from the class.
This seems like a complicated workaround. What other goals are you trying to achieve with this PR? Whould the simple change as it was in |
This is not a "complicated workaround". It is an official way to postpone initiation of "heavy" services. This method is inherited from Symfony and proxy classes are auto-generated with a PHP script provided by the Drupal core. https://symfony.com/doc/3.4/service_container/lazy_services.html This can be a solution but not in all cases. Have you tested this PR? Could you send me a link to a commit where you have troubles because of this? I am asking around in the Drupal community whether retrieving storage in a service's constructor is actually an undocumented bad practice because I keep seeing this in other contrib modules as well. Also, just imagine that you need storage in n+1 different methods in your service class, would you always write (Attached an updated test to #140) |
I had some quick conversation with @Jaesin about this pull request. Much like lazy services also work for working around circular dependencies, I don't think this is the best way, given that you need to re-generate the proxies when we would want to change the interface. There are some alternatives:
|
@dawehner Thanks for taking a look at this PR also. I also asked around in the Drupal community whether saving an instance of an entity storage to a property in a service's constructor is bad practice. TL;DR; I did not get a clear answer. Sascha Grossenbacher (berdir) wrote on Slack:
Okay, but what if I need one specific storage, let's say 3 different places in my service class. Should I dare to save it to a property in the constructor or let's retrieve it every time from the entity type manager?
There is no clear answer within these lines, there is no justification why you should use one over the other. Only a custom that can vary per developer (lsd. Commerce guys also use the same technique). Issus that he mentioned which could occur in testing can be eliminated by using Consequently, creating lazy services as a fix to this problem still seems a better option to me. |
We have a workaround for #140 by not injecting the service there is no hurry for this. I will test it and we can talk more about it after the current sprint. |
This has been fixed by #144 |
Fixes #140
I do not think the reported problem would require an extra test in this module. I mean we should not verify whether the reported by @Jaesin exist or not after this fixed gets merged. The service remains lazy loaded.
The latest Travis build: https://travis-ci.org/mxr576/apigee-devportal-drupal/builds/499723141