Skip to content

infrastructure: services cannot receive the injector without a static locator #22

Closed

Description

@schlessera

Context

Some services need on-demand instantiation through the injector (design principle 5). Today there is no clean way to inject the Injector itself: the container holds it under injector (src/Infrastructure/ServiceBasedPlugin.php:246-250), but asking the injector to build a service whose constructor takes Injector fails, because Injector is an interface with no binding.

All three plugins known to be built on this scaffold, including AMP and Web Stories, independently added a static Services locator, and use it inside their own composition roots to reach the injector (Services::get( 'injector' )). Principles 5 and 7 rule out such a locator; the missing capability is the reason it keeps appearing.

Scope

  • Make the plugin's own injector injectable: a constructor parameter typed Injector receives the same injector instance the plugin uses, configured by the infrastructure itself rather than by each composition root.
  • Document the pattern in the composition root as the supported alternative to a static locator.

Out of scope

  • Any static service locator.
  • Exposing the service container by injection.

Acceptance criteria

  • A service whose constructor takes Injector receives the plugin's injector instance; a test fails before the change and passes after.
  • Custom injectors passed to ServiceBasedPlugin are the ones injected (poka-yoke defaults, principle 3).

Verification

composer test
composer lint

Impact on generated plugins

No: this does not change an interface or convention generated plugins rely on.

2026-10-23: the container citation moved from :201-204 to :246-250 (lines as of the fix for this issue).

Activity

  1. added
    type: featA new capability or a change in behaviour.
    area: infrastructuresrc/Infrastructure: services, injector, views, autoloader. What generated plugins build on.
    agent-readyContext and acceptance criteria are complete enough for an agent to take this unattended.
    on Oct 22, 2026
  2. self-assigned this
    on Oct 23, 2026
  3. schlessera commented on Oct 23, 2026

    @schlessera
    MemberAuthor

    Picking this up on branch feat/22-inject-the-injector.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

agent-readyContext and acceptance criteria are complete enough for an agent to take this unattended.area: infrastructuresrc/Infrastructure: services, injector, views, autoloader. What generated plugins build on.priority: p2Wanted, not scheduled.type: featA new capability or a change in behaviour.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions