New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Usage of containers.override decorator #301
Comments
Hey @JarnoRFB , Yep, I was going to deprecate overriding of containers on declarative level. Thanks for bringing this up. Let me check what's going on with it now. |
I have fixed typed stubs (see #302 ). The fix is published as I thought about declarative container decorators and decided to deprecate them in favour of similar operations on instance level. The main reason for this is design improvement by avoiding a dualism in overriding container providers. I see the future of the framework on instance level for the containers. Please, upgrade to: c = BaseContainer()
c.override(OverrideContainer()) or: c = BaseContainer(provider1=..., provider2=...) I have added deprecation warnings for both |
@rmk135 Thanks for the clarification! I still have a few things I can't wrap my head around yet. I mainly use dependency injection, because I want to reuse my application in slightly different contexts, e.g. for different customers that use different data formats. When I now try to switch to instance level overriding, I make the main function require the container as an argument and return a CLI function. In the extension module, I override the container on the instance level, pass it to the main function and call the resulting CLI function. Because code is often clearer that explaining I created this little example https://github.com/JarnoRFB/di-overriding. Hope that makes sense. Glad to hear, if an obvious solution exists or if I am using things not the way the are meant to be used. |
@JarnoRFB , thanks for sharing code sample. That perfectly demonstrates the problem. Yep, |
@JarnoRFB I've made a PR with some refactoring to the sample repo JarnoRFB/di-overriding#1. I consolidated containers and used |
@rmk135 thanks a lot for looking at this and even presenting a possible solution. However, I believe that using The main challenge for this right now seems not to be the dynamic container overriding, but the sharing of configuration. In Spring, which was my first contact with dependency injection, I believe that is solved using kind of a global configuration, as you can access properties from configurations everywhere using Maybe it would then make sense to enable sharing configuration across containers, so that when one writes |
Agree. Well, there is no easy way to extend the configuration that way right now. I like the idea and will think of that as a future improvement. Having no good alternative for that case I think that the right thing is to "un-deprecate" I appreciate your feedback and arguments. Thanks for bringing this up. My sincere respect and gratitude. If you have any other thought - you're welcome anytime. |
@rmk135 Yes I believe that "un-deprecating" |
Done in Btw, there are two new providers: https://python-dependency-injector.ets-labs.org/providers/resource.html and https://python-dependency-injector.ets-labs.org/providers/dict.html. Closing the issue. Comment / re-open if needed. |
Hi,
I think in previous versions is was possible to do something like:
Afterwards
would contain all the overrides.
However, the typing now complains that
containers.override
wants a Container instance and not a class. Has overriding containers on the class level been deprecated, as it also seems to have been removed from the documentation?The text was updated successfully, but these errors were encountered: