Symfony2 documentation explains very well what is a service and container outbuildings. But in an application you often need to inject more services or settings. You've already said that it was easier to inject the service container directly rather than inject all dependencies one after the other? Here are the "for" and "against." Why not do it?
{
Second, it will use the service container in tests, or have a mock container if injected. By default, zim line tracking it does not contain services, so it will still mock those used by our service. We must therefore read the entire class not to forget dependencies. Which requires you to write code (useless) and more, while making the most complicated and time consuming to write tests ... and maintain.
Also, if you request a particular service to the container in many places, there is also decoupled from the rest of the code that we should. It is coupled with DIC instead of the class directly, but it always goes against the principle of injection depends. In which case inject the service container?
There are still cases where injecting the service container can be directly useful: when you have a service in a scope (scope) "container" that needs a service scope "request". Example, a Twig extension that would need to retrieve a Request URL.
The Twig extensions must be in the scope "container" because it depends on Twig which in this scope. But injecting Request directly request that the scope is reduced to "request". To solve this problem, it will inject the service container extension and check if a request is available:
class myextension extends \ Twig_Extension {private $ container; private $ request; public function __ construct (ContainerInterface $ container) {$ this-> container = $ container; if ($ this-> container-> isScopeActive ('request')) {$ this-> request = $ this-> zim line tracking container-> get ('request');}} / / ... }
10
$ This -> request = $ this -> container -> get ('request');
Note: Twig extensions do not benefit from lazy loading, and are always loaded, even if you issue a command. Since there is no Request a command, we need to verify its existence before trying to access it.
EDIT: As of symfony 2.4, a new scope, "request_stack" was introduced (see the article by Fabien Potencier). zim line tracking The problem described above is therefore moot. Incoming search terms: www ijecter com (1) Tags: Dependency Injection Service Container Symfony2 php
Indeed, zim line tracking with Symfony 2.4 (released 2 days after your article, I grant you) the defense of duress Scope of request service is not at all valid, zim line tracking there is now a service "request_stack" for landing zim line tracking has this problem.
Reply
You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> zim line tracking <acronym title=""> <blockquote cite=""> <b> <cite> <code class = "" title = "" data-url = ""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class = "" title = "" data-url = ""> <span class="" title="" data-url="">
Search for: Categories Uncategorized Javascript Symfony Latest Articles DotJs 2013 return on conferences. Create an RPC via RabbitMQ zim line tracking and Symfony2 useful Bundles Unit Test a bundle Symfony 2 Performance and Memcached in Symfony 2
Recent Articles DotJs 2013 return on conferences. zim line tracking Create an RPC via RabbitMQ and Symfony2 useful Bundles Unit Test a bundle Symfony 2 Performance and Memcached in Symfony 2 Blog Eleven Labs DotJs 2013 return on conferences. January 13, 2014 Dara Mehdy Create an RPC via RabbitMQ January 5, 2014 Jonathan Jalouzot Symfony2 and useful Bundles January 4, 2014 Marie Minasyan Keywords
acl admin generator AngularJS authentication bundle hidden doctrine dotJS drop ESI firewall Google i18n Injection dependencies temporary LswMemcacheBundle Javascript map / reduce mongodb memcached performance php phpunit RabbitMQ rockmongo RPC Service Container Sf2 symfony Symfony2 tutorial test translation virtualhost
No comments:
Post a Comment