mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-22 09:36:48 +03:00
Add docs and example
This commit is contained in:
parent
68a3ce14f9
commit
b1cd3272fc
|
@ -72,6 +72,20 @@ where ``examples/providers/configuration/config.yml`` is:
|
|||
.. literalinclude:: ../../examples/providers/configuration/config.yml
|
||||
:language: ini
|
||||
|
||||
Alternatively, you can provide a path to the YAML file over the configuration provider argument. In that case,
|
||||
the container will call ``config.from_yaml()`` automatically:
|
||||
|
||||
.. code-block:: python
|
||||
:emphasize-lines: 3
|
||||
|
||||
class Container(containers.DeclarativeContainer):
|
||||
|
||||
config = providers.Configuration(yaml_files=["./config.yml"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
container = Container() # Config is loaded from ./config.yml
|
||||
|
||||
:py:meth:`Configuration.from_yaml` method supports environment variables interpolation.
|
||||
|
||||
.. code-block:: ini
|
||||
|
|
25
examples/providers/configuration/configuration_yaml_init.py
Normal file
25
examples/providers/configuration/configuration_yaml_init.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
"""`Configuration` provider values loading example."""
|
||||
|
||||
from dependency_injector import containers, providers
|
||||
|
||||
|
||||
class Container(containers.DeclarativeContainer):
|
||||
|
||||
config = providers.Configuration(yaml_files=["./config.yml"])
|
||||
|
||||
|
||||
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"
|
Loading…
Reference in New Issue
Block a user