simple dependency injection library
Project description
simple-di
A simple, strictly typed dependency injection library.
Install
pip install simple_di
Usage
Examples:
from simple_di import inject, Provide, Provider
from simple_di.providers import Static, Callable, Configuration
class Options(Container):
cpu: Provider[int] = Static(2)
worker: Provider[int] = Callable(lambda c: 2 * c + 1, c=cpu)
@inject
def func(worker: int = Provide[Options.worker]):
return worker
assert func() == 5
assert func(1) == 1
Options.worker.set(2)
assert func() == 2
Options.worker.reset()
assert func() == 5
Options.cpu.set(1)
assert func() == 3
API
Type annotation supported
inject
Inject values into providers in function/method arguments.
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
simple_di-0.0.3.tar.gz
(3.9 kB
view hashes)
Built Distribution
Close
Hashes for simple_di-0.0.3-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e423bce22bcac0e705be8734ab2ad9aa3775e3c39684455d88f41766b6f11a5 |
|
MD5 | a679c74ffa844af7b3b31f1ef8259a37 |
|
BLAKE2b-256 | 4d1c943bf10f851dd151865990030f920196fc5b8da2b1ddf8d1ca3a3d1749f4 |