Using Extbase outside a frontend request 

Extbase expects a fully prepared frontend request. By the time an Extbase plugin runs, the frontend has resolved the page and built the TypoScript configuration that Extbase reads its settings from.

Outside that context, that preparation has not happened, and Extbase reacts in two different ways depending on which part of it is used. Controllers, views and anything else resolving plugin.tx_<extension> configuration fail outright. The persistence layer is deliberately allowed to run without a request. In a command or a middleware it has no configuration to draw on, so it limits its queries to storagePid 0 alone, unless the code names the pages itself.

Three contexts run into this, each with a different amount of the frontend available:

Extbase in backend modules

A request, but not a frontend one. The backend provides its own configuration, and Extbase runs in a supported but different mode.

Extbase on the command line

No request at all. Nothing of the frontend exists unless the command establishes it.

Extbase in middlewares

A request, but Extbase does not see it. The middleware can pass on what the request already knows, such as the site and the language.

Of the three, the backend module is the only context Extbase is designed for. Commands and middlewares use Extbase outside the context it expects. Each page describes what is available in that context, what has to be established before Extbase can be used, and when the work belongs somewhere else entirely.

Commands and middlewares have no Extbase settings, and a backend module has only the settings of its own module. Which configuration can be read instead is described in Reading configuration outside a frontend request.