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
There is a somewhat Guicey python-inject project. It's quite active, and a LOT less code then Spring-python, but then again, I haven't found a reason to use it yet.
Here is a small example for a dependency injection container that does constructor injection based on the constructor argument names:
http://code.activestate.com/recipes/576609-non-invasive-dependency-injection/
Simpler than a framework is the
@autowired
decorator.This decorator provides clean dependency injection and lazy initialization support.
It turns code like this:
into this:
It isn't a framework, so you there is zero setup and enforced workflows, though it doesn't provide injection contexts manipulation.
Disclosure: I'm the project maintainer.
pinject (https://github.com/google/pinject) is a newer alternative. It seems to be maintained by Google and follows a similar pattern to Guice (https://code.google.com/p/google-guice/), it's Java counterpart.
Besides that:
There's dyject (http://dyject.com), a lightweight framework for both Python 2 and Python 3 that uses the built-in ConfigParser