Usage With zend-servicemanager
zend-di is designed to play and integrate well with zend-servicemanager. When you are using zend-component-installer, you just need to install zend-di via composer and you're done.
Service Factories For DI instances
zend-di ships with two service factories to provide the
Zend\Di\Container\ConfigFactory: Creates a config instance by using the
Zend\Di\Container\InjectorFactory: Creates the injector instance that uses a
Zend\Di\ConfigInterfaceservice, if available.
use Zend\Di; use Zend\Di\Container; $serviceManager->setFactory(Di\ConfigInterface::class, Container\ConfigFactory::class); $serviceManager->setFactory(Di\InjectorInterface::class, Container\InjectorFactory::class);
Abstract/Generic Service Factory
This component ships with an generic factory
Zend\Di\Container\AutowireFactory. This factory is suitable as an abstract
service factory for use with zend-servicemanager.
You can also use it to create instances with zend-di using an IoC container (e.g. inside a service factory):
use Zend\Di\Container\AutowireFactory; (new AutowireFactory())->__invoke($container, MyClassname::class);
Found a mistake or want to contribute to the documentation? Edit this page on GitHub!