injector/README.rst

45 lines
1.4 KiB
ReStructuredText
Raw Normal View History

2010-11-25 14:04:56 +00:00
Injector - Python dependency injection framework, inspired by Guice
2010-11-27 00:19:16 +00:00
======================================================================
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.
2010-11-25 14:04:56 +00:00
2010-11-27 00:19:16 +00:00
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. As an
added benefit, Injector encourages nicely compartmentalised code through the
use of :class:`Module` s.
``foo``
2010-11-25 14:04:56 +00:00
2010-11-25 14:33:37 +00:00
While being inspired by Guice, it does not slavishly replicate its API.
2010-11-25 22:27:18 +00:00
Providing a Pythonic API trumps faithfulness.
2010-11-25 14:33:37 +00:00
2010-11-27 00:19:16 +00:00
Concepts
--------
For those new to dependency-injection and/or Guice, some of the terminology may
not be obvious. For clarification:
Injector:
pass
2010-11-25 14:33:37 +00:00
2010-11-27 00:19:16 +00:00
:class:`Binding`:
2010-11-25 22:27:18 +00:00
2010-11-27 00:19:16 +00:00
:class:`Provider`:
A means of providing an instance of a type. Built-in providers include
:class:`ClassProvider` (creates a new instance from a class),
:class:`InstanceProvider` (returns an instance directly)
2010-11-25 14:33:37 +00:00
2010-11-27 00:19:16 +00:00
At its heart, the :class:`Injector` is simply a dictionary, mapping types to
providers of instances of those types. This could be as simple as::
2010-11-25 14:33:37 +00:00
2010-11-27 00:19:16 +00:00
{str: str}
2010-11-25 14:33:37 +00:00
2010-11-27 00:19:16 +00:00
Footnote
--------
This framework is similar to snake-guice, but aims for simplification.
2010-11-25 14:33:37 +00:00
2010-11-27 00:19:16 +00:00
:copyright: (c) 2010 by Alec Thomas
:license: BSD
2010-11-25 14:33:37 +00:00