How can a list element in a Configuration provider be injected?
See original GitHub issueHello,
I have quite a nested configuration file that contains a lot of lists. I would like to inject a specific element into a provider, which would look like:
config = providers.Configuration(defaults={'index': 0, 'items': list('a', 'b', 'c')})
foo= providers.Factory(Foo, item=config.items[config.index])
However, I was prompted:
TypeError: 'dependency_injector.providers.Configuration' object is not subscriptable
Anyone has idea about this? Thank you.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Configuring dependency providers - Angular
The Creating and injecting services topic describes how to use classes as dependencies. Besides classes, you can also use other values such as...
Read more >Configuration provider - Dependency Injector
This page demonstrates how to use Configuration provider to inject the dependencies, load a configuration from an ini or yaml file, a dictionary, ......
Read more >How to work with lists in .NET dependency injection
NET dependency injection. Register multiple instances of an interface and resolve as an IEnumerable. We'll be doing the examples as a FizzBuzz ...
Read more >What is the best way to inject a list with google-guice?
I need to initialize my FormBuilder and notably a BuilderList (extending List<ShapeBuilder> ) with one instance of each class with google-guice. What is...
Read more >Spring - Injecting Collections - Baeldung
Besides registering the CollectionsBean, we also inject a new list by explicitly initializing and returning it as a separate @Bean configuration ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@clifflau1120 ,
I didn’t sleep well after was unable to implement
providers.Factory(Foo, option1=config.items[config.target].option1)
. I would like Dependency Injector to handle this case. I also didn’t like the internals ofConfiguration
provider, so:Configuration
provider.config.items[config.target].option1
use case. See example: https://github.com/ets-labs/python-dependency-injector/blob/master/examples/providers/configuration/configuration_itemselector.pyFeature is available in Dependency Injector
3.26.0
.Ok, sounds good. Thank you.