Package _Framework :: Module Dependency
[hide private]
[frames] | no frames]

Module Dependency

source code

Dependency injection framework.

The framework provides lously coupled passing of dependencies from providers to the objects that require them.

Dependencies are identified by keys, that are valid Python identifiers. Dependencies are provided via accessor functions, that in general will be called whenever they are needed.

Classes [hide private]
  DependencyError
  InjectionRegistry
  dependency
Data descriptor that provides a given dependency looking as an attribute.
  Injector
  RegistryInjector
  InjectionFactory
Functions [hide private]
 
get_dependency_for(obj, name, default=None) source code
 
depends(**dependencies)
Decorates a method where dependencies are passed as keyword parameters.
source code
 
inject(**k)
Inject returns a InjectorFactory that can generate Injectors to inject the provided keys at different levels.
source code
Variables [hide private]
  _global_injection_registry = InjectionRegistry()
  __package__ = '_Framework'
Function Details [hide private]

depends(**dependencies)

source code 

Decorates a method where dependencies are passed as keyword parameters. Dependencies are specified as keywords with an optional accessor function or None if required. Dependencies can be injected or passed directly as keyword parameters. Example:

   class HttpServer(object):
       @depends(http_port = const(80))
       def listen(http_port = None):
           print "Listening on", http_port

   server = HttpServer()
   server.listen()
   server.listen(http_port = 8000)
   with inject(http_port = const(8000)).everywhere():
       server.listen()

Produces the output:

   Listening on port 80
   Listening on port 8000
   Listening on port 8000

inject(**k)

source code 

Inject returns a InjectorFactory that can generate Injectors to inject the provided keys at different levels. The values to inject are specified as keyword parameters mapping keys to given nullary callables that will be used to access the dependency when needed.