I can't get my custom Middleware invoked!

I am trying to write a custom app with a Middleware to interpret some cookies set from other software on the same domain.

I am following the documentation, but the Middleware is not invoked. I have tracked the problem down to the dependency injection closure not being invoked (the one inside the registerService call).

I’m not exactly a fluent PHP developer, so I may misunderstand this service injection stuff. I am creating the application like “new MyApp();”.

namespace OCA\CrowdSSO\AppInfo;
use \OCP\AppFramework\App;
use \OCP\AppFramework\Middleware;
//use \OCA\CrowdSSO\Middlewware\CrowdMiddleWare;
use OCP\Util;

class CrowdMiddleware extends Middleware {
    public function beforeController($controller, $methodName){
	Util::writeLog('crowdsso','Hello World 2!',Util::DEBUG);
	parent::beforeController($controller, $methodName);
    }
}
class CrowdSSO extends App {
    /**
     * Define your dependencies in here
     */
    public function __construct(array $urlParams=array()){
        parent::__construct('crowdsso', $urlParams);
	Util::writeLog('crowdsso','Hello World Constructor!',Util::DEBUG);	
        $container = $this->getContainer();
        $container->registerService('CrowdMiddleware', function($c){
		Util::writeLog('crowdsso','Hello World Closure!',Util::DEBUG);
            return new CrowdMiddleware();
        });

        $container->registerMiddleware('CrowdMiddleware');
    }
}

$app = new CrowdSSO();

Well, I figured it out. In some owncloud forum it was discussed that apps can only put middlewares into their own controllers. Which was not obvious to me, it’s not how Django’s middlewares work, and it’s not mentioned in the documentation (or I didn’t find it in there).

Now I have to figure out another way to analyze cookies on every request.