Still continue appear message warning: Deprecated #89
Comments
@wtabata Yes. We're emitting it at that location for a number of reasons:
Because We have been recommending for literally years that developers not pull dependencies from the composed service locator, and instead directly inject their dependencies. We recommend this for several reasons:
While we recognize that during early development of a controller, it's often easier to pull stuff out of the service locator, we feel that for the reasons stated above, it's an anti-pattern, and will lead to costly maintenance eventually. For these reasons, we'll be removing this capability in zend-mvc v3. If you rely on that capability, you have several choices:
Alternately: start updating your code to remove this usage, as your code and maintenance will benefit from the changes. |
@weierophinney terrific!! |
Thanks for the extensive explanation! But still I have an issue regarding to "Alternately: start updating your code to remove this usage...". I already have all dependencies injected via factory in constructor and I never use getServiceLocator() method (but I am using ControllerPlugins). |
Which plugins are you using, specifically?
|
Redirect, FlashMessenger, Identity, Params and Layout. |
Small offtopic, but related:
What possibilities to sign setter to be clear is required for this class (by constructor is clear)? |
Hi,
Into a business (or service, or model) layer, i'm more than agree with this assumption, dependencies must be required and explicit as much. But for front controllers, as some MVC layers promote them, constructor dependency injection can be a huge waste of resources. Given a typical CRUD controller, where the post / update action requires a form as dependency. Why should we inject a sometimes very sophisticated form into the controller, when we just need to perform a list or get action ? While some of our controllers does not respect some fundamentals from the single responsibility design principle, i'm convinced that strict DI is not a design pattern to apply on, and the use of the service locator seem's a fair trade. The default action based zend-expressive approach helps a lot to solve this, by writing consistent request-front objects :) |
@ronan-gloo We provided an answer to that scenario (conditional dependencies) in ZF 2.3, via lazy services. The recommendation is to use lazy services when you have a dependency that is only used in some code paths; these are injected as normal dependencies, i.e., via constructor or setter injection. The benefit they provide is that the "heavy" service is not retrieved from the service container until first access of any method on the service instance. So, yes, the recommendation of injecting all services vs pulling them from a composed service locator still stands. The addition of lazy services to zend-servicemanager was what allowed us to unequivocally recommend the practice. |
Hi, |
I think we should correct documentation with the correct method, so we avoided continue to develop wrong code. |
Hey Doug, The fact that you pre-inject things that you won't use indicates some SRP Marco Pivetta On 30 March 2016 at 03:04, Doug Bierer notifications@github.com wrote:
|
In " \zend-mvc\src\Controller\AbstractController.php on line 258 "
Let me see if I got it right. I can not use getServiceLocator() in the controller? I have to send all pendencies by factories? Even extending AbstractActionController?
The text was updated successfully, but these errors were encountered: