OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

dependency-injector: How to provide fallbacks for configuration values?

  • Thread starter Thread starter zwirbeltier
  • Start date Start date
Z

zwirbeltier

Guest
I’m in the process of introducing dependency-injector to some old projects. In one of them I have a config value that has a fallback to another value and a default value. Essentially I’m looking for an equivalent of:

Code:
value = config.get("value", config.get("fallback", "default"))

I’m especially interested in how to pass such a value to a service defined in a provider.DeclarativeContainer.

While the docs provide many examples on how to add configuration from different sources I couldn’t find a lot about accessing config values. I also looked at the docstrings of the methods of provider.Configuration() but without success.
<p>I’m in the process of introducing dependency-injector to some old projects. In one of them I have a config value that has a fallback to another value and a default value. Essentially I’m looking for an equivalent of:</p>
<pre class="lang-py prettyprint-override"><code>value = config.get("value", config.get("fallback", "default"))
</code></pre>
<p>I’m especially interested in how to pass such a value to a service defined in a <code>provider.DeclarativeContainer</code>.</p>
<p>While <a href="https://python-dependency-injector.ets-labs.org/" rel="nofollow noreferrer">the docs</a> provide many examples on how to <a href="https://python-dependency-injector.ets-labs.org/providers/configuration.html" rel="nofollow noreferrer">add configuration from different sources</a> I couldn’t find a lot about accessing config values. I also looked at the docstrings of the methods of <code>provider.Configuration()</code> but without success.</p>
 
Top