Note that there are some explanatory texts on larger screens.

plurals
  1. POHelp with Dependency Injection in MVC app
    primarykey
    data
    text
    <p>Zend Framework/Doctrine 2 application.:</p> <pre><code>/app /modules /blog /controllers /BlogController.php /domain /entities /services /PostService.php /repositories </code></pre> <p>PostService is responsible for basic CRUD opterations, dealing directly with entities and the EntityManager to abstract the business and persistence logic out of my controllers. </p> <p>If possible, I would like to keep my services as POPOs. What's the best way to access/inject the EntityManager in my service class? I'm new to DI, hence this question. The EntityManager is accessible as a bootstrap resource in my controllers.</p> <p>Should I just write a abstract class for services to access the EntityManager? Should I write a class to instantiate my services, injecting the EntityManager via the constructor/setter?... which would involve an interface for my services. Should I use a DI framework? If so, which one and how? </p> <p>Or is there another, better way to do this?</p> <p>I have done reading on dependency injection but still don't fully grasp it in this context.</p> <hr> <h2>Update (12th Jan 2011)</h2> <p>So this is my current working solution: I have an action helper called Resource, it is a helper for retrieving resources from the bootstrap, or you can manually added resources to it: <a href="http://pastie.org/1450851" rel="nofollow">http://pastie.org/1450851</a></p> <pre><code>$this-&gt;_helper-&gt;Resource('em'); // get EntityManager </code></pre> <p>Can someone please provide some insight into the performance impact of storing bootstrap resources locally within the helper class? Am I over doing it?<br> TODO: Refactor the resourcesMap out of the class.</p> <p>And I have an action helper for loading services: <a href="http://pastie.org/1450855" rel="nofollow">http://pastie.org/1450855</a><br> TODO: Add checks before attempting to load the service.</p> <p>Please provide some criticism on the above :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload