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.6.tar.gz
(4.2 kB
view hashes)
Built Distribution
Close
Hashes for simple_di-0.0.6-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0c40d3ee685c04ccd77b87d3c610fd744dbe6e987105aeb71b82cdfba17d8c5 |
|
MD5 | a84c3b63bc36898cc61c6f5639d43237 |
|
BLAKE2b-256 | a81b29f3adc5b20e7e18096eaaefa5a014a322a485e1d68a190d16c643371b39 |