'Fastapi : how to get app instance in router?

I want to get app instance in my router file , what should I do ?

My main.py is

...
app = FastAPI()
app.machine_learning_model = joblib.load(some_path)
app.include_router(some_router)
...

Now I want to use app.machine_learning_model in some_router's file , what should I do ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source