-
Notifications
You must be signed in to change notification settings - Fork 83
Optionally allow overriding of dependencies #90
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
Optionally allow overriding of dependencies #90
Conversation
Hi! Could you explain, why you chose to use Do you think |
Hey,
And generally I think it's more clear that when configuring you just set the global behavior during configuration so you are not bothered to think about every line if you need override or not, you just register your service and it works, even if you duplicate it or it gets removed from parent config etc. What are your thoughts do you think this approach has some drawbacks? |
recommendation to points 1 and 2 - when overriding, wrap the Binder with a proxy with the same interface which handles this case ? that way you don't have to spread override=True all over the place, and still allow the override to be as an argument to the binding methods |
Can you elaborate? Do you mean applying changes with the current approach - "allow_override" or the approach for "override" in Binder methods? Can you simple code example? |
Ok, so the main reason is you have different composable configurations which can override some bindings in some cases. I see, I get it. I'll merge it today. |
Might be an over-complication, but allows for both suggested methods in the discussion. Instead of self.allow_override (which given self._bindings should probably be self._allow_override to denote it is internal property) change bind method on Binder to be
and add the class
And when wanting to override:
|
Relates to (#65 discussion).
Preface
When configuring injector for different environments often times you need to use a the same core configuration and swap only a few dependencies. This also happens for specific tests when you need to mock something or tweak some service's configuration.
The current implementation only allows for installing an exising config with
binder.install
and then build up upon it without overriding dependencies.This unflexibility forces developers to always create configurations from scratch for every environment or for specific tests which leads to code duplications and when introducing new dependencies in your core configuration, you have to specify them in every other config as well.
Solution
With the following changes configurations are composable with the ability to allow overriding of dependencies for example: