Replies: 1 comment
-
For anyone looking for an answer, I found it myself by looking at the source code. You can simply do the following: from typing import ContextManager
container[ContextManager[MyDep]] = MyDep Maybe this could be added to the documentation
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In order to add cleanup to a dependency in a container we have to register it using
context_dependency_definition
decorator and use thetry: yield ... finally: cleanup
pattern.I'm wondering if this could be avoided for objects already defined as context manager and providing
__enter__
and__exit__
functions. For exampleIMO this could make it easier to record dependencies that are contextual and requires some cleanup
Beta Was this translation helpful? Give feedback.
All reactions