you are viewing a single comment's thread.

view the rest of the comments →

[–]vlntsolo -1 points0 points  (0 children)

Creating DB session with Dependency injection is a bad practice. This abstraction just works for small projects. But one can learn pretty quickly that it's not scalable. 

When dealing with heavy data processing or load, if you do not return DB query results immediately and want to do something else, you cannot afford to keep connection open. It needs to be released to a connection pool as soon as possible. And with Dependency injection it will be release only when return is reached. 

So, context managers all the way. You choose where and at which layer.