zend framework2 - ZF2 ServiceManager Factory Object Instance stored or Lazy Loaded? -


i working on large project db has many tables accessed in different modules different reasons. came idea of using service manager point factory classes instantiate tablegateway models , return them on request, lazy loading tablegateway model.

however still unsure whether or not factories in servicemanager lazy loaded or they're instantiated servicemanager?

i.e., if have in configuration file

array(     'service_manager' => array(         'factories => array(             'giftcard_table' => 'giftcard\factory\giftcardtablefactory',         ),     ), ); 

will new instance of giftcard\factory\giftcardtablefactory created every time call $sm->get('giftcard_table')? or gets instantiated along servicemanager @ beginning of every http request regardless of whether call $sm->get('giftcard_table') or not?

the factories instantiated when request them via service manager's get method. method calls create method, in turn calls createfromfactory method in case of requesting factory. per highlighted line on last link, can see indeed instantiate factory @ time requested. can see stores factory. because services fetched service manager shared default. shared means same instance returned on subsequent requests. can think of cache. can disable this if desire, such instance of given service created on every request.

in configuration file:

// configuration omitted 'service_manager' => array(     /* ... */      'shared' => array(         'myfactory' => false,     ) ); 

by accessing service manager object:

$service_manager->setshared('myfactory', false); 

some time ago wrote an article service manager, includes section concept of shared services (near bottom), may useful you.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -