Closed
Description
Sometimes I don't care about service name at all, e.g. when I decorate service or when I make service which is meant to be injected by CompilerPass (listeners, command handlers, ....). If I have multiple services for the same class, I'm not able to simply use class name as a service name.
Does it make sense to introduce something like anonymous services (ServicesConfigurator
):
final public function anonymous(string $class)
{
return $this->set(uniqid(), $class)->private();
}
? (service name should be determined for tests, but I want to show the idea).
Also current configuration of decorated services is not well-compatible with anonymous services above. I want to see something like
return function (ContainerConfigurator $c) {
$c->anonymous(CacheFooDecorator::class)
->decorate(Foo::class)
->args(
decorated(), // injects Foo service
ref('memcache'),
// ...
);
};