with container.enter_scope("request") as state:
db = solved.execute_sync(executor=SyncExecutor(), state=state)
print(db) # <generator object PostgresFactory.__call__ at 0x7f52f19657e0>
But __call__ is not handled and I got just a raw generator.
Workaround
It works if I simply put __call__ as dependent call:
with container.enter_scope("request") as state:
db = solved.execute_sync(executor=SyncExecutor(), state=state)
print(db)
# Postgres init-ed
# <__main__.Postgres object at 0x7f1d09713400>
# Postgres closed
Example
Here I use factory (dependent call) as a configurable class with
__call__
: https://github.com/maxzhenzhera/di/blob/5302c792bad2f3ee0dc8fae6116756e088b95f87/docs_src/bug_callalbe_class_instance_not_handled_as_factory.pyBut
__call__
is not handled and I got just a raw generator.Workaround
It works if I simply put
__call__
as dependent call:Result:
Handling of this case fixed in one Fastapi`s PR: https://github.com/tiangolo/fastapi/pull/1365