0

I need a help with Zend\Di;

I'm tired on the task of write factories to my application using the Zend\ServiceManager, I want to understand how work the configuration in MVC environment of Zend\Di.

I see this post of @Ocramius, with some configuration in the module.config.php, in the top key di:

<?php return array( 'di' => array( 'allowed_controllers' => array( // this config is required, otherwise the MVC won't even attempt to ask Di for the controller! 'Application\Controller\GreetingController', ), 'instance' => array( 'preference' => array( // these allow injecting correct EventManager and ServiceManager // (taken from the main ServiceManager) into the controller, // because Di doesn't know how to retrieve abstract types. These // dependencies are inherited from Zend\Mvc\Controller\AbstractController 'Zend\EventManager\EventManagerInterface' => 'EventManager', 'Zend\ServiceManager\ServiceLocatorInterface' => 'ServiceManager', ), ), ), // remaining config ); 

Anyone can post a url to the doc of this configuration or more detailed examples here?

1 Answer 1

1

If you have a lot of different controllers and have a lot of services to choose from, then the ones with Configuration or Annotation should be the choices in this link: https://github.com/ralphschindler/Zend_DI-Examples

I think you should look at some libraries like Aura.Di or Pimple. They provide even powerful DI containers.

If you have minimal services to inject, use initializers. Check this out: http://akrabat.com/zend-framework-2/zendservicemanager-configuration-keys/

Sign up to request clarification or add additional context in comments.

4 Comments

Is not the same thing and can't have much initializers, each are executed on every request to the service manager.
If you have a lot of different controllers and have a lot of services to choose from, then the ones with Configuration or Annotation should be the choices in this link:github.com/ralphschindler/Zend_DI-Examples
Thanks, I will try use this in the key "di"w of the module.config.php. Is sad that not have a well documented way to make this. Change your response or response again to I choose as the correct.
Check my latest answer. Yes, the examples dont have much documentation. It is just to give an idea of what is possible. You should take a look at Aura.Di or Pimple, if you have'nt already, they are pretty powerful too.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.