simple dependency injection library
Project description
simple-di
A simple 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.1.tar.gz
(3.2 kB
view hashes)
Built Distribution
Close
Hashes for simple_di-0.0.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9528a40e84fa7b1ae4499f35c324303e4c2ef23766d7a92b756e3713c7320c67 |
|
MD5 | d4c1d60fc6692125667936cb86b7f143 |
|
BLAKE2b-256 | 061f4b798aa6fe1537c898c962d833352e66d454cc6594fb0f76137821ea8599 |