Lightweight dependency injection container.
Project description
Injectulate
Lightweight dependency injection framework relying on type annotations for dependency resolution.
Installation
pip install injectulate
Usage
Simple use case
from injectulate import Builder
class Foo:
pass
builder = Builder()
container = builder.build()
foo = container.get(Foo)
Simple dependencies
from injectulate import Builder
class Foo:
pass
class Bar:
# Type annotation is required as it's used to resolve the dependency.
def __init__(self, dependency: Foo):
pass
container = Builder().build()
bar = container.get(Bar)
A class with a dependency on Container will always result in the container injecting itself.
Binding class to inheriting class
from injectulate import Builder
from abc import ABC
class AbstractClass(ABC):
pass
class Implementation(AbstractClass):
pass
builder = Builder()
builder.bind(AbstractClass).to(Implementation)
container = builder.build()
impl = container.get(AbstractClass)
Binding to factory method
from injectulate import Builder, Container
from abc import ABC
class AbstractClass(ABC):
pass
class Implementation(AbstractClass):
def __init__(self, c: Container):
pass
builder = Builder()
builder.bind(AbstractClass).to(lambda c: Implementation(c))
container = builder.build()
impl = container.get(AbstractClass)
Suggestions
Are welcomed
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
Injectulate-0.1.1.tar.gz
(41.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file Injectulate-0.1.1.tar.gz.
File metadata
- Download URL: Injectulate-0.1.1.tar.gz
- Upload date:
- Size: 41.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.1 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a065530366335036072efb628c608debe518a381967c1006aa376b892754ba59
|
|
| MD5 |
f5cb7ea700fe021a3e31ee3f16ac12e4
|
|
| BLAKE2b-256 |
367072c84fa286800609902dd0d05e015ca0d721cd6c578443c014ad52634d49
|
File details
Details for the file Injectulate-0.1.1-py3-none-any.whl.
File metadata
- Download URL: Injectulate-0.1.1-py3-none-any.whl
- Upload date:
- Size: 29.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.1 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f40c7526f5e45407ed589a6de26c5e150e3f63388d62c5afe7a5d73f817791a5
|
|
| MD5 |
e97c6e99f3f98e6cf100688ef20c518c
|
|
| BLAKE2b-256 |
80949e8a3a7f5f8c22ed93d4be535a42bdf3c9c9d7ef8d533be95b5d0df816e5
|