Using Aura.Di

Aura.Di provides a serializable dependency injection container with the following features:

Installing Aura.Di

Aura.Di implements PSR-11 as of version 3. To use Aura.Di as a dependency injection container, we recommend using zendframework/zend-auradi-config, which helps you to configure its container. First, install the package:

$ composer require zendframework/zend-auradi-config


To configure Aura.Di, create the file config/container.php with the following contents:

use Zend\AuraDi\Config\Config;
use Zend\AuraDi\Config\ContainerFactory;

$config = require __DIR__ . '/config.php';
$factory = new ContainerFactory();
return $factory(new Config($config));

Your bootstrap (typically public/index.php) will then look like this:

require 'vendor/autoload.php';
$container = require 'config/container.php';
$app = $container->get(Zend\Expressive\Application::class);
require 'config/pipeline.php';
require 'config/routes.php';

For more information, please see the zend-auradi-config documentation