3.1.10. Migrating from 2.x to 3.x

Aura.Di 3.x is largely similar to 2.x, but there are some backwards-compatibility breaks, as well as some new features.

3.1.10.1. BC Breaks

3.1.10.1.1. Instantiation

The way the container is instantiated has been changed from this ...

use Aura\Di\Container;
use Aura\Di\Factory;
use Aura\Di\ContainerBuilder;

$di = new Container(new Factory);

// or

$container_builder = new ContainerBuilder();
$di = $container_builder->newInstance(
    array(),
    array(),
    $auto_resolve = false
);

... to this:

use Aura\Di\ContainerBuilder;

$container_builder = new ContainerBuilder();

// use the builder to create and configure a container
// using an array of ContainerConfig classes
$di = $container_builder->newConfiguredInstance([
    'Aura\Cli\_Config\Common',
    'Aura\Router\_Config\Common',
    'Aura\Web\_Config\Common',
]);

3.1.10.1.2. setter vs setters

Use of $di->setter in 2.x is now $di->setters in 3.x. Please note there is an additional s in the end.

3.1.10.1.3. Automatic Locking

The container now calls lock() automatically when you call get() or newInstance(), so make sure everything is lazy-loaded, or else you will run into something like cannot modify container when locked.

3.1.10.1.4. Config vs ContainerConfig

Aura\Di\Config in 2.x is now Aura\Di\ContainerConfig in 3.x.

3.1.10.2. Features

3.1.10.2.1. lazyGetCall()

Example taken from Radar:

$di->params['Radar\Adr\Handler\RoutingHandler']['matcher'] = $di->lazyGetCall('radar/adr:router', 'getMatcher');

Here the value assigned to matcher is taken from the RouterContainer getMatcher() method.

3.1.10.2.2. Instance Factories

An instance factory creates multiple instances of the same class; refer the docs for more information.