-- A.J. Brown <[email protected]> wrote
(on Thursday, 14 October 2010, 05:09 PM -0400):
> I've been doing some research on lazy loading resources in Zend Framework,
> and it seems that the decision has been made that resources that should be
> lazy loaded should not be a part of the bootstrapping mechanism.  I'm not
> sure that I agree with this idea, so I'd like to re-open the discussion.
> 
> For example, I currently have code which makes use of Zend_Service_LiveDocx.
>  For Dependency Injection, I would rather the class be configured outside of
> the methods that are calling it, so creating a resource seems to be the best
> bet.  However, it's a "waste of time" to initialize the LiveDocx class 99%
> of the time, since only a small portion of the application uses it.  In this
> particular case I believe the overhead will be very minimal compared to the
> added complexity/duplication of doing it any other way, but that's not
> necessarily true in other cases.
> 
> Being that resources are able to load their dependencies themselves using
> the Boostrap mechanism, wouldn't it make more sense to lazy load ALL
> resources by default?  Of course this becomes an issue when you're using
> _init functions in your Bootstrap class to configure the application, and
> they don't return any resources.  So, it seems that there needs to be some
> distinction between initialization and resources.  Or, perhaps, a
> distinction between resource classes, and init functions within the Boostrap
> file.
> 
> Thoughts?

The design of Zend_Application was to initialize resources needed on
each request, plain and simple. 

What you describe is more of a Service Container and/or DI Container.
You can actually use these _with_ Zend_Application to augment it -- a
number of folks have injected the Symfony DI Container into
Zend_Application in order to achieve similar results:

  * http://www.whitewashing.de/blog/articles/118
  * http://blog.starreveld.com/2009/11/using-symfony-di-container-with.html
  * 
http://losohome.wordpress.com/2010/01/22/integrating-symfony-dependency-injection-service-container-with-zend-framework/

-- 
Matthew Weier O'Phinney
Project Lead            | [email protected]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

Reply via email to