yiisoft / injector

PSR-11 compatible injector
https://www.yiiframework.com/
BSD 3-Clause "New" or "Revised" License
43 stars 18 forks source link

Multiple optional containers #14

Closed roxblnfk closed 4 years ago

roxblnfk commented 4 years ago

What do you think about adding the ability to set multiple containers in the injector?

class Injector {
    public function __construct(ContainerInterface $container, ContainerInterface ...$containers) {}
}

$injector = new Injector($container);
// or
$injector = new Injector($container1, $container2);
// or
$injector = new Injector(...$containers);

I know that i can take a composite container, but out of the box it will be easier.

In addition, the container itself may be a optional and multiple parameter.

class Injector {
    public function __construct(ContainerInterface ...$containers) {}
}

It seems to me that this would be useful for those cases when the set of potential parameters is predetermined and the transfer of the container is already superfluous

samdark commented 4 years ago

I don't think we should implement it. It's rare use-case, there are composite containers available.