python-injection 0.10.8

Creator: bradpython12

Last updated:

Add to Cart

Description:

pythoninjection 0.10.8

python-injection



Fast and easy dependency injection framework.
Installation
⚠️ Requires Python 3.12 or higher
pip install python-injection

Motivations

Easy to use
No impact on class and function definitions
Easily interchangeable dependencies (depending on the runtime environment, for example)
No prerequisites

Quick start
Simply apply the decorators and the package takes care of the rest.
from injection import injectable, inject, singleton

@singleton
class Printer:
def __init__(self):
self.history = []

def print(self, message: str):
self.history.append(message)
print(message)

@injectable
class Service:
def __init__(self, printer: Printer):
self.printer = printer

def hello(self):
self.printer.print("Hello world!")

@inject
def main(service: Service):
service.hello()

if __name__ == "__main__":
main()

Resources

Basic usage
Testing
Advanced usage
Utils
Integrations
Concrete example

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.