What is a Pythonic way for Dependency Injection?

后端 未结 9 2141
终归单人心
终归单人心 2020-12-02 06:57

Introduction

For Java, Dependency Injection works as pure OOP, i.e. you provide an interface to be implemented and in your framework code accept an instance of a c

9条回答
  •  青春惊慌失措
    2020-12-02 07:56

    I think that DI and possibly AOP are not generally considered Pythonic because of typical Python developers preferences, rather that language features.

    As a matter of fact you can implement a basic DI framework in <100 lines, using metaclasses and class decorators.

    For a less invasive solution, these constructs can be used to plug-in custom implementations into a generic framework.

提交回复
热议问题