Dependency injection as a formal pattern is less useful in Python than
in other languages, primarily due to its support for keyword
arguments, the ease with which objects can be mocked, and its dynamic
nature.
That said, a framework for assisting in this process can remove a lot
of boiler-plate from larger applications. That's where Injector can
help. It automatically and transitively provides keyword arguments
with their values. As an added benefit, Injector encourages nicely
compartmentalized code through the use of Module s.
While being inspired by Guice, it does not slavishly replicate its
API. Providing a Pythonic API trumps faithfulness.
我喜欢这个简单整洁的框架。
http://pypi.python.org/pypi/injector/
Spring Python是基于Java的Spring框架和Spring安全性的分支,面向Python。此项目当前包含以下功能:
我还没有使用它,但是Spring Python框架是基于Spring并实现Inversion of Control。
Python项目中似乎还有一个Guice:snake-guice
相关问题 更多 >
编程相关推荐