Skip to main content

IOCynergy

Python module for IOC container using dependency injection (uses python 3+ type hints, supported until Python3.7)

Easy way to initialize your services

from cynergy import container

class TestClass:
    pass

class ParentClass:
    def __init__(self, test_class: TestClass):
        self.test_class = test_class

instance = container.get(ParentClass)  # Returns TestClass initialized as singleton

print(type(instance))  # ParentClass
print(type(instance.test_class))  # TestClass

Access to your configuration from any service

from cynergy import container
from cynergy.config import Config, MemoryConfig
from cynergy.attributes import arguments

@arguments(db=Config('db_name'),host=Config('hostname'))
class DbConnector:
    def __init__(self, db: str, host: str):
        self.db = db
        self.host = host

container.initialize(MemoryConfig({
    "db_name": "LocalDbName",
    "hostname": "localhost"
}))

instance = container.get(DbConnector)

print(instance.db)  # LocalDbName
print(instance.host)  # localhost

** You can implement your own configuration provider (for exmaple you can create DbConfigProvider which provides your settings from the db)

Manually register special types

from cynergy import container

class Original:
    pass

class Other:
    pass

container.register_class(Original, Other)

instance = container.get(Original)

print(type(instance))  # Other

Register collection of services

from typing import List
from cynergy import container

class HandlerBase:
    pass

class SomeHandler1(HandlerBase):
    pass

class SomeHandler2(HandlerBase):
    pass

class SomeService:
    def __init__(self, handlers: List[HandlerBase]):
        self.handlers = handlers

container.register_many(HandlerBase, [SomeHandler1, SomeHandler2])

instance = container.get(SomeService)

print(type(instance.handlers))  # list
print(type(instance.handlers[0]))  # SomeHandler1
print(type(instance.handlers[1]))  # SomeHandler2

Download files

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

Source Distribution

cynergy-1.2.0.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

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

cynergy-1.2.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file cynergy-1.2.0.tar.gz.

File metadata

  • Download URL: cynergy-1.2.0.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.0

File hashes

Hashes for cynergy-1.2.0.tar.gz
Algorithm Hash digest
SHA256 eda11957e6f0690c700a9c0057f4921b4aceea136038d3d0217d3c180aa5deca
MD5 ed686de8c32a048d048446ec1ba0710b
BLAKE2b-256 94be78b52c95dfafa30fd21dabd651a457aa0274d408fc7a63ffeb850d5bfc88

See more details on using hashes here.

File details

Details for the file cynergy-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: cynergy-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.0

File hashes

Hashes for cynergy-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3517dd78e4baea3638a893765aef97e1039b1348b7b49adcf14748d6dbe38b1e
MD5 d18220929145e14c5c3c826ffea4c919
BLAKE2b-256 4467f0b35b46100b20f7d947eac5e7c9573c82d1f349efbe62d2ccd460127810

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 files

1.1.13

2 files

1.1.12

1 file

1.1.11

1 file

1.1.10

2 files

1.1.9

2 files

1.1.8

2 files

1.1.7

1 file

1.1.6

1 file

1.1.5

1 file

1.1.4

1 file

1.1.3

1 file

1.1.2

1 file

1.1.1

1 file

1.1.0

1 file

1.0.3

3 files

1.0.2

2 files

1.0.1

2 files

1.0.0

2 files

Supported by

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