Yet Another Python Dependency Injection
Project description
YAPYDI: Yet Another Python Dependency Injection
Why? Just need a simpler DI, checked some existing ones, not a fun, so developed this one.
Why DI in python? Well, it is NOT for everyone. It is always an good idea for loose coupling for user and implmentation.
How to use it
Install
pip install yapydi
Basic usage
from yapydi import enable_di, bean, injected, Injected
@bean()
def world() -> str:
return "World"
@injected
def hello_world(world : str = Injected[str]):
print("Hello {}!".format(world))
@enable_di
def main():
hello_world()
if __name__ == "__main__":
main()
Advanced usage
from yapydi import enable_di, bean, BeanRegistry
@bean(name="my_bean_name")
def world() -> str:
return "World"
def hello_world():
registry = BeanRegistry.get_instance()
print("Hello {}!".format(registry.one_by_name("my_bean_name")))
@enable_di
def main():
hello_world()
if __name__ == "__main__":
main()
Check more details inside * injection_test.py * please.
How does it work
Doing bean definition and injection with annotation power. @bean() annotation will get the bean to be registered. @enable_di will init the beans, and @injected will be hooked so the injection can happen. BeanRegistry is the only place for retrieve beans by name type or both.
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 Distributions
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 yapydi-0.1.3-py3-none-any.whl.
File metadata
- Download URL: yapydi-0.1.3-py3-none-any.whl
- Upload date:
- Size: 26.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7cc5058c171f3c0b06d60a1d3dd571c53303e2e32ddc23cbc91fe2e20102b15
|
|
| MD5 |
e9ffb04e6e2309512353cc36b1df82ea
|
|
| BLAKE2b-256 |
2dc1ac07d747b1eec44525697537dc597a73b07abc4ad0bbbdb0671ac94ed88f
|