Is there a framework equivalent to Guice (http://code.google.com/p/google-guice) for Python?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
If you want a guice like (the new new like they say), I recently made something close in Python 3 that best suited my simple needs for a side project.
All you need is an @inject on a method (__init__ included of course). The rest is done through annotations.
https://pypi.python.org/pypi/py3njection
I recently released a neat (IMHO) micro library for DI in python:
https://github.com/suned/serum
As an alternative to monkeypatching, I like DI. A nascent project such as http://code.google.com/p/snake-guice/ may fit the bill.
Or see the blog post Dependency Injection in Python by Dennis Kempin (Aug '08).
I made a lib to do this https://github.com/ettoreleandrotognoli/python-cdi I hope that helps
It's available on pypi: https://pypi.python.org/pypi/pycdi
With it you can make injections with python2
And using type hints from python3
If you just want to do dependency injection in Python, you don't need a framework. Have a look at Dependency Injection the Python Way. It's really quick and easy, and only c. 50 lines of code.
I like this simple and neat framework.
http://pypi.python.org/pypi/injector/