python-dependency-injector
python-dependency-injector copied to clipboard
Question: how to dynamically add providers to root container
This is just a question, since i'm unable to figure this out on my own by just reading the docs. I'm currently trying to rewrite one of my apps to use dependency injector. I have an app context which is known at runtime and needs to be added to the one container I have in my app. The container is declared in an additional file. The entry file then imports the container, sets it up and is ment to add (or override, whatever) the actual app context into the container. It doesn't seem like I can use a dynamic container here, because that one would need to be initialized directly within the main file, correct? I have something like:
The dynamic container examples don't seem to show a way to have a dynamic container as the only container in your application. I'd have trouble typing my code mypy-ready in that case. Could you please tell me how this is possible? I'd imagine that it work via one of two ways, but both seem to not be exactly ment to do this:
- Via a dynamic container within a declarative container. I don't want to wrap a container within a container just for one attribute.
- Creating an Object provider on a declarative container just to be overridden from the main script. That is possible, but doesn't seem to be the way overriding was ment to be used. Thanks for your support.