<?php
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
class Foo
{
}
class Bar
{
}
$fooDefinition = new Definition('Foo');
// In 2.X it was setScope() set to prototype
$fooDefinition->setShared(false);
$fooDefinition->setPublic(true);
$barDefinition = new Definition('Bar');
$barDefinition->setPublic(true);
// set definitions in container builder
$containerBuilder = new ContainerBuilder();
$containerBuilder->setDefinition('foo', $fooDefinition);
$containerBuilder->setDefinition('bar', $barDefinition);
// calling bar service
$bar1 = $containerBuilder->get('bar');
$bar2 = $containerBuilder->get('bar');
dump($bar1 === $bar2);
// calling foo service
$foo1 = $containerBuilder->get('foo');
$foo2 = $containerBuilder->get('foo');
dump($foo1 === $foo2);
^ true
^ false