ivankorobkov / python-inject

Python dependency injection
Apache License 2.0
671 stars 77 forks source link

Duplicate Binding Exception - Overwrite Bindings #76

Closed nikordaris closed 3 years ago

nikordaris commented 3 years ago

Is there a way to overwrite bindings? For testing I want to be able to binder.install(prod_binder) and then selectively overwrite a subset of the prod bindings with test bindings instead. Right now i have to duplicate all the bindings just to set a test specific one for a single binding. I can do better groupings of my prod bindings but it would be nice if i can just overwrite ones.

ivankorobkov commented 3 years ago

Hi!

Now there is no way to override bindings. In my experience overriding typically makes a project configuration difficult to reason about.

However, if you really need overriding you can make a pull request :-)

nikordaris commented 3 years ago

I ended up grouping my bindings into different functions and using the binder.install so that i can reuse bindings in test and change others with mock bindings. I think this is a reasonable solution and your concerns about readability are definitely valid. Closing this issue.