Task #102008
closedInterface Alias is shared by default
0%
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?
Updated by Benjamin Franzke about 1 year ago
- Status changed from New to Rejected
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.