Project

General

Profile

Actions

Task #102008

closed

Interface Alias is shared by default

Added by Timo Borer about 1 year ago. Updated about 1 year ago.

Status:
Rejected
Priority:
Should have
Assignee:
-
Category:
Backend API
Target version:
-
Start date:
2023-09-22
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
12
PHP Version:
8.2
Tags:
Complexity:
Sprint Focus:

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?

Actions #1

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.

Actions

Also available in: Atom PDF