question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can a list element in a Configuration provider be injected?

See original GitHub issue

Hello,

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:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
rmk135commented, Aug 3, 2020

@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 of Configuration provider, so:

Feature is available in Dependency Injector 3.26.0.

0reactions
rmk135commented, Aug 4, 2020

Ok, sounds good. Thank you.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found