python-dependency-injector
python-dependency-injector copied to clipboard
Configuration is evaluated on container declaration when using Container provider
Configuration provider will throw ValueError: Missing required environment variable "MYENV" when declaring a container that uses another container as a dependency. The following snippet exemplifies the behavior:
# test.yaml
a: "${MYENV}"
# main.py
class A(containers.DeclarativeContainer):
config = providers.Configuration(strict=True, yaml_files=["./test.yaml"])
# Commenting out these two lines does not throw
class B(containers.DeclarativeContainer):
a = providers.Container(A) # Throws ValueError: Missing required environment variable "MYENV"
# Anything after this does not matter.
Expected behavior: The script doesn't throw an exception until the container is instantiated.