Aglyph — Dependency Injection for Python¶
| Release: | 1.1.1 |
|---|
Aglyph is a Dependency Injection framework for Python 2.5+, supporting type 2 (setter) and type 3 (constructor) injection.
Aglyph runs on CPython 2.5 - 3.3, and on recent versions of the PyPy, Jython, IronPython, and Stackless Python variants. See Aglyph testing summary for a complete list of the Python versions and variants on which Aglyph has been tested.
Aglyph can assemble prototype components (a new instance is created every time), singleton components (the same instance is returned every time), and borg components (a new instance is created every time, but all instances of the same class share the same internal state).
Aglyph can be configured using a declarative XML syntax, or programmatically in pure Python.
Aglyph is not a “full stack;” only dependency injection support is provided.
Table of Contents¶
- Getting started with Aglyph
- 1. Download and install Aglyph
- 2. Download, extract, and run the movielisterapp application
- 3. Make some general improvements to the movielisterapp application
- 4. Add Dependency Injection support to the movielisterapp application
- 5. Make changes to the movielisterapp application
- 6. Suggested next steps
- Aglyph API reference
- aglyph — Dependency Injection for Python
- aglyph.assembler — The Aglyph component assembler
- aglyph.binder — The Aglyph component binder
- aglyph.cache — Simple object caching support for Aglyph
- aglyph.component — Defining components and their dependencies
- aglyph.context — Defining component contexts
- aglyph.compat.ipyetree — an ElementTree parser for IronPython
- Aglyph cookbook
- Use Aglyph with Python 2 or Python 3, and with all popular variants
- Use 3rd-party classes/functions as components
- Define dependencies in XML for built-ins not described by the Aglyph DTD
- Exploit the flexibility of a Reference
- Be careful with <eval>, functools.partial, Evaluator, and Reference
- Respect Unicode and character encodings in XML configuration
- Avoid circular dependencies
- Protect injected dependencies from being modified by reference
- Write wrappers for objects that are not created by importable classes or functions
- Aglyph testing summary
See also
- Inversion of Control Containers and the Dependency Injection pattern
- The definitive introduction to Dependency Injection
- Python Dependency Injection [PDF]
- Alex Martelli’s introduction to Dependency Injection (and alternatives) in Python
Download¶
Download the latest distutils source or built distribution of Aglyph on SourceForge.
Clone the Aglyph Mercurial repository from BitBucket.
See Aglyph testing summary for a complete list of the Python versions and variants on which Aglyph has been tested.
Aglyph versioning¶
The Aglyph version is always defined as the __version__ member of the aglyph/__init__.py module:
>>> import aglyph
>>> aglyph.__version__
'1.1.1'
The Aglyph context DTD includes the version in the filename and in a header comment. This version represents the most recent Aglyph version in which the DTD itself was changed.
Aglyph increments its MAJOR.MINOR.MICRO version (i.e. aglyph.__version__) as follows:
- A transparent (non-public) API change increments the MICRO version.
- A backwards-compatible public API change increments the MINOR version.
- Any non-backwards-compatible API change increments the MAJOR version.
As a result of this approach:
- You can always upgrade/downgrade to a higher/lower MICRO version, assuming MAJOR and MINOR are the same.
- You can always upgrade to a higher MINOR version, assuming MAJOR is the same.
- Downgrading to a lower MINOR version (assuming MAJOR is the same) may require application and/or configuration changes (for example, if you took advantage of a new feature that is not available in the lower version).
- Upgrading/downgrading to a higher/lower MAJOR version will always require application and/or configuration changes.