from fastapi import Depends, FastAPI
class MyDependency:
def __init__(self):
# Perform initialization logic here
pass
def some_method(self):
# Perform some operation
pass
def get_dependency():
# Create and return an instance of the dependency
return MyDependency()
app = FastAPI()
@app.get("/example")
def example(dependency: MyDependency = Depends(get_dependency)):
dependency.some_method()
For the code snippet above, does subsequent visits to /example create a new instance of the MyDependency object each time? If so, how can I avoid that?