Documentation: https://python-injection.remimd.dev
pip install python-injectionSimply apply the decorators and the package takes care of the rest.
frominjectionimportinjectable, inject, singleton@singletonclassPrinter:
def__init__(self):
self.history= []
defprint(self, message: str):
self.history.append(message)
print(message)
@injectableclassService:
def__init__(self, printer: Printer):
self.printer=printerdefhello(self):
self.printer.print("Hello world!")
@injectdefmain(service: Service):
service.hello()
if__name__=="__main__":
main()