Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Simple Dependency Injection for python

Project Description

CNS Dependency Injection is a very simple way to store and inject services into your software.

It looks like this for Flask (dumb example, but you should get the point):

from di.helpers import get_service, add_service
from di.decorator import service, inject
from flask import Flask

app = Flask(__name__)
add_service('router', app.route)

@service('adder')
def adder(*args):
  sum = 0
  for arg in args:
    sum += arg
  return sum

router = get_service('router')

@router('/adds')
def adds():
  sum = get_service('adder')([1,2,3])
  return "hello " + repr(sum)

get_service('app').run()

If you are going to @inject into a class, do it on the __init__ function. @service can be used with classes or functions.

Release History

Release History

This version
History Node

0.1.4

History Node

0.1.3

History Node

0.1.2

History Node

0.1.1

History Node

0.1.0

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
CNSdi-0.1.4.tar.gz (5.8 kB) Copy SHA256 Checksum SHA256 Source Sep 21, 2013

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting