mercredi 28 janvier 2015

Why to use Service Containers?

Having:



$serviceA = new ServiceA();
$serviceB = new ServiceB();
$serviceC = new ServiceC($serviceA, $serviceB);


Why there is some ServiceContainers? What is the purpose for them like Pimple (Pimple's website just says its a DIC, dont tell why it exists) for example.



$container = new Pimple();

$container['service_a'] = $container->share(function(){
return new ServiceA();
});

$container['service_b'] = $container->share(function(){
return new ServiceB();
});

$container['service_c'] = $container->share(function($container){
return new ServiceC($container['service_a'], $container['service_b']);
});

Aucun commentaire:

Enregistrer un commentaire