Skip to main content

Yet another Dependency Injection (IOC) component for Python

Project description

https://travis-ci.org/glorpen/glorpen-di.svg?branch=master https://readthedocs.org/projects/glorpen-di/badge/?version=latest

Another Dependency Injection library for Python.

This package has following three guidelines:

  • any class configured by Container mechanism should not be modified in any way

  • there is no need for external services definition files for Container

  • no Container compiling and service tagging - we have introspection and dynamic language for this task

And so this package provides:

  • no xml configuration

  • no annotations (more cons than pros)

  • no changes to services code

Official repositories

For forking and other funnies.

BitBucket: https://bitbucket.org/glorpen/glorpen-di

GitHub: https://github.com/glorpen/glorpen-di

Supported design patterns

Service instance can be created by:

  • factory service

  • calling class object with arguments

Instance options can be altered by:

  • constructor arguments

  • setters

  • calling methods

  • using configurator service

Each service has defined scope, service cannot request other service from narrower scope.

Injecting services and parameters

from glorpen.di import Container

class MyParamService(object):
    pass

class MyService(object):
    def __init__(self, obj, text, value):
        super(MyService, self).__init__()
        print("service instance: %s" % obj)
        print("container parameter: %s" % text)
        print("provided value: %s" % value)

c = Container()

c.add_service(MyParamService)
c.add_parameter('my-param', "value from container")
c.add_service(MyService).kwargs(obj__svc=MyParamService, text__param="my-param", value="defined value")

c.get(MyService)

Running snippet will print:

service instance: <__main__.MyParamService object at 0x7f2fef6e9828>
container parameter: value from container
provided value: defined value

See https://glorpen-di.readthedocs.io/en/latest/ for code examples and more documentation.

Project details


Download files

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

Source Distribution

glorpen-di-1.5.0.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

glorpen_di-1.5.0-py2.py3-none-any.whl (8.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file glorpen-di-1.5.0.tar.gz.

File metadata

  • Download URL: glorpen-di-1.5.0.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.3

File hashes

Hashes for glorpen-di-1.5.0.tar.gz
Algorithm Hash digest
SHA256 326faf42ff7f680874f8c05030b37211f99479f0657565b861849d1dea91c98e
MD5 c72e5f4e1d5a4958bee19e168f563a6a
BLAKE2b-256 610ec5ef1ade094da834c053b6252c173a18fb9681240fc79b34b3ff9ffb7113

See more details on using hashes here.

File details

Details for the file glorpen_di-1.5.0-py2.py3-none-any.whl.

File metadata

  • Download URL: glorpen_di-1.5.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.3

File hashes

Hashes for glorpen_di-1.5.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 a887ada64799f19d3ecadd976c5ff929bbeabf82950176a58e17157574e37b44
MD5 5dfe562d01706e4976ad8d0c8836bb24
BLAKE2b-256 3b48428ab08f8d82d7e8a7f752effcc3a5976aef29a12c759e0afe37f8e3cb15

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page