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, Factory, Configuration
class Options(Container):
cpu: Provider[int] = Static(2)
worker: Provider[int] = Factory(lambda c: 2 * int(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.
Arguments:
- squeeze_none: default False. Treat None value passed in as not passed.
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.5.tar.gz
(4.0 kB
view hashes)
Built Distribution
Close
Hashes for simple_di-0.0.5-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e1a06a53f005a6f7dca04317efff1f59157ee9d38b5bdab2d513bffd0fef5e0 |
|
MD5 | 938f358ac8be37b6eb43c477ccf4353a |
|
BLAKE2b-256 | 036da96c96f9d1581772a9e41c5a1aacbb92b516f0253b1ea8bf9f24c4ba028f |