Skip to content

Conversation

@sbuerk
Copy link
Member

@sbuerk sbuerk commented May 16, 2025

It's a good practice to define interfaces and provide a default
implementation making xclass strategies, stubbing or mocking in
tests and similar techniques easier. Default implementation, if
provided, should be configured in the DI configuration as alias
for the interface, not done for the ConfigurationInterface on
the default implementation Configuration.

TYPO3 SingeltonInterface stems from old times before DI has
been introduced to TYPO3 and has been used to mark classes as
shared (only instanciated onces) within GeneralUtilitiy,
something is the default behaviour for services in DI as long
as not configured otherwise. Having ConfigurationInterface
and Configuration DI aware makes the SingeltonInterface
obsolete.

Services implementing SingletonInterface are automatically
configured as public: true by a TYPO3 DI compiler pass and
needs to be set manually when removing the interface from a
service.

This change ...

  • Remove SingletonInterface from Configurtion in favour
    of default shared: true of the DI.
  • Use Symfony AsAlias php attribute on Configuration to
    mark it as the default ConfigurationInterface service,
    addtional setting the service as public: true to allow
    retrieval using GeneralUtility::makeInstance().

That prepares towards retrieving services by DI either as
constructor or inject* methods in the future.

It's a good practice to define interfaces and provide a default
implementation making xclass strategies, stubbing or mocking in
tests and similar techniques easier. Default implementation, if
provided, should be configured in the DI configuration as alias
for the interface, not done for the `ConfigurationInterface` on
the default implementation `Configuration`.

TYPO3 `SingeltonInterface` stems from old times before DI has
been introduced to TYPO3 and has been used to mark classes as
`shared` (only instanciated onces) within `GeneralUtilitiy`,
something is the default behaviour for services in DI as long
as not configured otherwise. Having `ConfigurationInterface`
and `Configuration` DI aware makes the `SingeltonInterface`
obsolete.

Services implementing `SingletonInterface` are automatically
configured as `public: true` by a TYPO3 DI compiler pass and
needs to be set manually when removing the interface from a
service.

This change ...

* Remove `SingletonInterface` from `Configurtion` in favour
  of default `shared: true` of the DI.
* Use Symfony `AsAlias` php attribute on `Configuration` to
  mark it as the default `ConfigurationInterface` service,
  addtional setting the service as `public: true` to allow
  retrieval using `GeneralUtility::makeInstance()`.

That prepares towards retrieving services by DI either as
constructor or `inject*` methods in the future.
@sbuerk sbuerk merged commit 5a0a79c into main May 16, 2025
9 checks passed
@sbuerk sbuerk deleted the stefan-2 branch May 16, 2025 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants