Dependency Injection in Python: The Java Guy’s Perspective

You can have as many injectors as you have, and each injector instance can be supplied with as many dependency module configurations as you wish:if __name__ == '__main__': real_injector = Injector(AppModule()) test_injector = Injector([AppModule(), TestAppModule()]) real_logic = real_injector.get(BusinessLogic) real_logic.do_stuff() test_logic = test_injector.get(BusinessLogic) test_logic.do_stuff()resulting in:Api calledthe api returned a result: 42Demo Api calledthe api returned a result: 24The EndI will stop here..I hope, if not really having managed to convince you, to have given you a slightly different perspective on things..Until next time!Related ResourcesInversion of Control Containers and the Dependency Injection patternPythonic Dependency Injection: A Practical Guide — Sune Andreas Dybro Debel — MediumPython 3 Patterns, Recipes and Idioms — Python 3 Patterns, Recipes and IdiomsDependency injection and inversion of control in Python — Dependency Injector 3.14.2 documentationalecthomas/injectorsuned/serumets-labs/python-dependency-injectorRobertoPrevato/rodi. More details

Leave a Reply