Skip to main content

Dependency Injection Container Library

Project description

Injecta

Dependency Injection (DI) Container written in Python. Main component of the Pyfony Framework.

Installation

$ pip install injecta

Simple container initialization

(The following steps are covered in the ContainerInitializerTest)

To start using Injecta, create a simple config.yaml file to define your DI services:

parameters:
  api:
    endpoint: 'https://api.mycompany.com'

services:
    mycompany.api.ApiClient:
      arguments:
        - '@mycompany.api.Authenticator'

    mycompany.api.Authenticator:
      class: mycompany.authenticator.RestAuthenticator
      arguments:
        - '%api.endpoint%'
        - '%env(API_TOKEN)%'

Then, initialize the container:

from injecta.container.ContainerBuilder import ContainerBuilder
from injecta.config.YamlConfigReader import YamlConfigReader
from injecta.container.ContainerInitializer import ContainerInitializer

config = YamlConfigReader().read('/path/to/config.yaml')

containerBuild = ContainerBuilder().build(config)

container = ContainerInitializer().init(containerBuild)

Use container.get() to finally retrieve your service:

from mycompany.api.ApiClient import ApiClient

apiClient = container.get('mycompany.api.ApiClient') # type: ApiClient   
apiClient.get('/foo/bar')

Advanced examples

  1. Configuring services using parameters
  2. Service autowiring
  3. Using service factories
  4. Tagged services

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

injecta-0.8.0b2.tar.gz (24.3 kB view details)

Uploaded Source

Built Distribution

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

injecta-0.8.0b2-py3-none-any.whl (49.5 kB view details)

Uploaded Python 3

File details

Details for the file injecta-0.8.0b2.tar.gz.

File metadata

  • Download URL: injecta-0.8.0b2.tar.gz
  • Upload date:
  • Size: 24.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.0 CPython/3.7.6 Windows/10

File hashes

Hashes for injecta-0.8.0b2.tar.gz
Algorithm Hash digest
SHA256 6e0ba6dff84fbe295caf3dfa3f075fca33aa3ef2c7b83641fd91f8cb01d244e1
MD5 6125d185e30ddad3f833f5ad8ab961f6
BLAKE2b-256 bd6bd3ae517f8bd3665e929af44829a79edfb8e35b4301b7ae473c8cb2c40c1d

See more details on using hashes here.

File details

Details for the file injecta-0.8.0b2-py3-none-any.whl.

File metadata

  • Download URL: injecta-0.8.0b2-py3-none-any.whl
  • Upload date:
  • Size: 49.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.0 CPython/3.7.6 Windows/10

File hashes

Hashes for injecta-0.8.0b2-py3-none-any.whl
Algorithm Hash digest
SHA256 20ef46e1767d5592a92d086dfa5f65ef2ac57b6a0780a9c5d829895c57e8cf7d
MD5 9d68f3c269dfbd69ae153232a2221a11
BLAKE2b-256 9c6da2ae2efbffb97b0fa03a11bacf273b10a2795e434e0ac814742a6dec5f2e

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