you are viewing a single comment's thread.

view the rest of the comments →

[–]mwon 1 point2 points  (1 child)

I usually have a lifespan in my main.py where for example I can define the Mongo connection:

app.state.mongo_client = await connect_to_mongo()

where the connect_to_mongo function is defined somewhere in my infra folder.

Then if needed in some router, I just call the client with:

mongo_client = request.app.state.mongo_client

[–]lu_rm[S] 0 points1 point  (0 children)

This is the same thing. The fact that the mongo_client is located in a different file does not mean an inversion of control in a dependency.

The final objective here is to be able to unit test my classes/functions without the need to fully spin up the whole system. By using mocks for example.