Issue Task Under Review

#111633Provide page routers via PageRouterFactory with injected dependencies

Benni Mack 11/27/26, 08:59 updated 11/27/26, 09:51

Description

Site->getRouter() creates a new PageRouter for every call via GeneralUtility::makeInstance(), and the PageRouter fetches all of its dependencies with makeInstance() as well. The router can not take part in dependency injection, and nothing it builds up survives the call.

This is noticeable when many URIs are generated for the same site, for instance in menus: with an expression in “limitToPages” of a route enhancer, every generateUri() call creates a new ExpressionLanguage Resolver. Measured on a test site, this is about 90 µs of about 150 µs per generated link.

Proposal:
  • Add a PageRouterFactory service, which creates page routers with their dependencies injected and keeps one router per site and context (held weakly).
  • Require all dependencies in the constructor of PageRouter (breaking).
  • Let Site->getRouter() return the router of the factory, and inject the factory in core services instead of calling Site->getRouter().
  • Create the “limitToPages” resolver once per router and hand over the page and site language on each evaluation.

Reviews 1

History 02

  1. Gerrit Code Review pushed patch set 1 for main to change 98096 status New Under Review 11/27/26, 09:01

  2. Gerrit Code Review pushed patch set 2 for main to change 98096 11/27/26, 09:51