Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm exploring dependency injection and trying to make the exercise as pythonic as possible; existing dependency injection frameworks seem very java-like. I've made some pretty good progress building my own framework, but I could really use a model project to validate the framework against. An ideal suggestion would be something that is hard without dependency injection, but is otherwise conceptually trivial.

share|improve this question
IMO, Some design patterns are over-rated. Dependency injection is one of those that arise naturally (it is being invented all the time), and, if you do not need it, then you will not have to reinvent it. –  Job Jan 15 '11 at 16:20
@Job: I basically agree, and in most cases, function composition is all the dependency injection a pythonista needs. On those rare cases where the glue needs to be a bit more decoupled, a bit of library code seems like it would be helpful, but there aren't any good libraries for this for python... I could apply my framework to the hairy ball I'm inventing it for, and surely I will, but i'd like something a bit less hairy to test it against. –  TokenMacGuy Jan 15 '11 at 16:28
add comment

1 Answer

The reason most dependency injection frameworks are Java-like is because Java is not a dynamic language. At least for unit testing in dynamic languages, stubbing and mocks are just as useful in Python as dependency injection. Arguably more so, since they don't force you to adopt a more-complex-than-necessary design.

For things other than dependency injection, the answer changes. But if you have no problem to solve, why are you writing code? Isn't it better to start with a problem to solve, and then work on a solution?

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.