Closed MadJlzz closed 3 years ago
Hey @MadJlzz ,
Did you look at Selector
provider https://python-dependency-injector.ets-labs.org/providers/selector.html?
Here is a container from your gist:
class Container(containers.DeclarativeContainer):
configuration = providers.Configuration()
if configuration.profile == "anthos":
stream = providers.Singleton(
PostgreSQLStream
)
else:
stream = providers.Singleton(
BigQueryStream
)
With the Selector
provider it will look like this:
class Container(containers.DeclarativeContainer):
configuration = providers.Configuration()
stream = providers.Selector(
configuration.profile,
anthos=providers.Singleton(PostgreSQLStream),
bigquery=providers.Singleton(BigQueryStream),
)
This exactly what I wanted! What about using this question to add an example in the documentation? (in the example category I mean) I can do it!
What about using this question to add an example in the documentation? (in the example category I mean)
Do you mean example with the Selector
provider?
This exactly what I wanted!
Ok, very good :)
There is an example with the Selector
here https://github.com/ets-labs/python-dependency-injector/tree/master/examples/miniapps/movie-lister.
There is also a tutorial showing how to build it step-by-step https://python-dependency-injector.ets-labs.org/tutorials/cli.html
Okay, I guess I really need to clean my glasses before creating an issue. Thanks a lot for the support!
No problems, you're welcome.
Most of the examples and providers take their origin from the issues like that. Thanks for raising that one. That's not a bad idea to have an example with Selector
provider better promoted.
Feel free to open another one if you see something not working, or not clear, or you just need an advice.
Hello,
I've searched through you're documentation but it seems not be possible at the moment to provide specific implementation of a service whenever we reach a certain condition with a value coming from a property file.
What I am intending to do with that is something like:
Here's what I am trying to do: https://gist.github.com/MadJlzz/22f977a6fd91e48d3c120dd9de9510f9
I know it is not working but I guess you will understand what I've tried to do. I've also understand that
providers.Configuration
is to load properties from a file and inject those inside one of the dependencies we are wishing to create. (so bad use in my example)If not possible at the moment, it could be a nice feature, no?