diff --git a/examples/providers/configuration/config.json b/examples/providers/configuration/config.json new file mode 100644 index 00000000..5d79c0b6 --- /dev/null +++ b/examples/providers/configuration/config.json @@ -0,0 +1,6 @@ +{ + "aws": { + "access_key_id": "KEY", + "secret_access_key": "SECRET" + } +} diff --git a/examples/providers/configuration/configuration_json.py b/examples/providers/configuration/configuration_json.py new file mode 100644 index 00000000..54dbd1a2 --- /dev/null +++ b/examples/providers/configuration/configuration_json.py @@ -0,0 +1,27 @@ +"""`Configuration` provider values loading example.""" + +from dependency_injector import containers, providers + + +class Container(containers.DeclarativeContainer): + + config = providers.Configuration() + + +if __name__ == "__main__": + container = Container() + + container.config.from_json("./config.json") + + assert container.config() == { + "aws": { + "access_key_id": "KEY", + "secret_access_key": "SECRET", + }, + } + assert container.config.aws() == { + "access_key_id": "KEY", + "secret_access_key": "SECRET", + } + assert container.config.aws.access_key_id() == "KEY" + assert container.config.aws.secret_access_key() == "SECRET" diff --git a/examples/providers/configuration/configuration_json_init.py b/examples/providers/configuration/configuration_json_init.py new file mode 100644 index 00000000..a69b92c2 --- /dev/null +++ b/examples/providers/configuration/configuration_json_init.py @@ -0,0 +1,25 @@ +"""`Configuration` provider values loading example.""" + +from dependency_injector import containers, providers + + +class Container(containers.DeclarativeContainer): + + config = providers.Configuration(json_files=["./config.json"]) + + +if __name__ == "__main__": + container = Container() + + assert container.config() == { + "aws": { + "access_key_id": "KEY", + "secret_access_key": "SECRET", + }, + } + assert container.config.aws() == { + "access_key_id": "KEY", + "secret_access_key": "SECRET", + } + assert container.config.aws.access_key_id() == "KEY" + assert container.config.aws.secret_access_key() == "SECRET"