Added support for registering middlewares.