title: FastApi middleware on different folder not working
body: <p>I,m getting this error when I try to run my FastApi api.</p>
  <blockquote>
  <p>app = cls(app=app, **options)
  TypeError: 'module' object is not callable</p>
  </blockquote>
  <p>I'm trying to add a middleware on other folder separeted from main.py and don't know why isn't working. Otherwise when I add the middleware code into main.py works without problems. Here is my code, thank you for your help and excuse my english.</p>
  <p>main.py</p>
  <pre><code>from fastapi import FastAPI
  from fastapi import Depends, FastAPI, HTTPException
  from fastapi import Request
  from routers import rutas
  from utils import CheckApiKey
  from utils.CheckApiKey import check_api_key
  
  app = FastAPI()
  app.add_middleware(CheckApiKey, dispatch=check_api_key) &lt;--- Here calling middleware
  app.include_router(rutas.router)
  
  
  if __name__ == &quot;__main__&quot;:
    import uvicorn
  
    uvicorn.run(&quot;main:app&quot;, host=&quot;127.0.0.1&quot;, port=8000, reload=True)
  </code></pre>
  <p>Middleware</p>
  <pre><code>from fastapi import Request
  
  async def check_api_key(request: Request, call_next):    
  
    print(&quot;ok&quot;)
    response = await call_next(request) 
  
    return response
  </code></pre>