Clean Framework · DOCUMENTATION
Wire dependencies explicitly
Wire dependencies explicitly
Steps
Use constructor injection and register application factories before freezing the container. Do not connect to a provider or start a session while registering dependencies.
// Inside composition, with these application dependencies already constructed.
$container->factory(DocumentationController::class, static fn (): DocumentationController =>
new DocumentationController($documents, $markdown, $views, $csrf, $categories)
);
$container->freeze();Use request-scoped or transient state for request-specific mutable values. Never retain a current user inside a singleton. See Container and the complete composition example.
Verify
Construct the kernel in an isolated test and assert that no session, runtime directory, database, or network call has started.
Editorial provenance
Source: resources/guides/injection.md. Source SHA-256: d54e6be6ce93cce46f37eb1e011c68a50e0e36cd27d0ab270c29ec1ae950831d.
Knowledge-base application source; editorial checkpoint 2026-10-20. See candidate status and adoption boundary.