import dependency_injector.containers as dic
import dependency_injector.providers as dip
class UnitOfWork:
...
class TestUnitOfWork(UnitOfWork):
...
class ApplicationContainer(dic.DeclarativeContainer):
unit_of_work_class = dip.Callable(UnitOfWork)
uow = dip.Factory(unit_of_work_class)
class TestApplicationContainer(ApplicationContainer):
unit_of_work_class = dip.Callable(TestUnitOfWork)
container = TestApplicationContainer()
print(container.uow())
with container.unit_of_work_class.override(TestUnitOfWork):
print(container.uow())
The output:
<__main__.UnitOfWork object at 0x110ae9ed0>
<__main__.UnitOfWork object at 0x110ae9ed0>
I would expect that container.uow() to return an instance of TestUnitOfWork, since container is an instance of TestApplicationContainer which has unit_of_work_class = dip.Callable(TestUnitOfWork).
container.unit_of_work_class.override(TestUnitOfWork) also doesn't work, as you can see...
The output:
I would expect that
container.uow()
to return an instance ofTestUnitOfWork
, since container is an instance ofTestApplicationContainer
which hasunit_of_work_class = dip.Callable(TestUnitOfWork)
.container.unit_of_work_class.override(TestUnitOfWork)
also doesn't work, as you can see...