Skip to content

462 Config.from_value() #465

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/main/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ Development version
configuration files with ``${ENV_NAME:default}`` format.
See issue `#459 <https://github.com/ets-labs/python-dependency-injector/issues/459>`_.
Thanks to `Maksym Shemet @hbmshemet <https://github.com/hbmshemet>`_ for suggesting the feature.
- Add method ``Configuration.from_value()``.
See issue `#462 <https://github.com/ets-labs/python-dependency-injector/issues/462>`_.
Thanks to Mr. `Slack Clone <https://disqus.com/by/slackclone/>`_ for bringing it up
in the comments for configuration provider docs.

4.32.3
------
Expand Down
11 changes: 11 additions & 0 deletions docs/providers/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,17 @@ Loading from an environment variable
:lines: 3-
:emphasize-lines: 18-20

Loading a value
---------------

``Configuration`` provider can load configuration value using the
:py:meth:`Configuration.from_value` method:

.. literalinclude:: ../../examples/providers/configuration/configuration_value.py
:language: python
:lines: 3-
:emphasize-lines: 14-15

Loading from the multiple sources
---------------------------------

Expand Down
24 changes: 24 additions & 0 deletions examples/providers/configuration/configuration_value.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""`Configuration` provider values loading example."""

from datetime import date

from dependency_injector import containers, providers


class Container(containers.DeclarativeContainer):

config = providers.Configuration()


if __name__ == '__main__':
container = Container()

container.config.option1.from_value(date(2021, 6, 13))
container.config.option2.from_value(date(2021, 6, 14))

assert container.config() == {
'option1': date(2021, 6, 13),
'option2': date(2021, 6, 14),
}
assert container.config.option1() == date(2021, 6, 13)
assert container.config.option2() == date(2021, 6, 14)
Loading