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
Project details
Release history Release notifications | RSS feed
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.12a1.tar.gz
(27.2 kB
view hashes)
Built Distribution
injecta-0.8.12a1-py3-none-any.whl
(56.4 kB
view hashes)
Close
Hashes for injecta-0.8.12a1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e548dc98ced09ab59e5c1bb4d42aa9b2ece2b6e69a5311867e5350d182242aa8 |
|
MD5 | 656a68500178d62a67f6d35ac4f6bcd4 |
|
BLAKE2b-256 | e88db02c50ee71d98927cfa1aae5163d0b1237b995cac2d9612c7065dc0d25e1 |