#102008Interface Alias is shared by default
Description
Normally, a Service is only shared when it extends the `SingletonInterface` or set directly.
This Service below acts as a singleton, but is not expected to be one as it doesn’t extend the `SingletonInterface`.
My\Extension\Domain\Interface\MyServiceInterface:
alias: My\Extension\Service\MyService
public: true
To achieve it you need to add the following:
My\Extension\Service\MyService:
shared: false
Wouldn’t it make more sense to also make the service shared: false if it is aliased and only shared if it uses the SingletonInterface?
Reviews 0
No change resolves or names this issue in its commit message, and no comment links one.
History 1
-
Benjamin Franzke commented and changed status
NewRejected 09/25/23, 05:38
No, sorry, we dont want to change symfony/DI semantics here. All services are shared by default (like Singletons) and that will stay.
The Singelton interface is pretty much useless, once we’re ready with migrating all services and tests to dependency injections (instead of relying on GeneralUtility::makeInstance lookups).
And interface aliases are really not meant to be used for prototypes, they are intended for services-interfaces.
If you need interchangable data objects, then a distinct factory object is the better choice.
Hope that’s fine.