injector
https://pypi.org/project/injector/
Injector - Python dependency injection framework, inspired by Guice
https://github.com/python-injector/injector
Pythonのdependency injectionフレームワーク injectorのExampleを素振り💉 おー、injector.getで依存が与えられた上でインスタンスができるぞ!を書いた
injectorのFull Example
デコレータ @inject
https://injector.readthedocs.io/en/latest/api.html#injector.inject
Decorator declaring parameters to be injected.
__init__へのデコレート
This decorator is to be used on class constructors
Injector クラス
https://injector.readthedocs.io/en/latest/api.html#injector.Injector
イニシャライザ
modules引数
a configuration module or iterable of configuration modules. Each module will be installed in current Binder using Binder.install().
getメソッド
https://injector.readthedocs.io/en/latest/api.html#injector.Injector.get
getはrootのオブジェクトを作るためのもの。rootのオブジェクトが作る依存は@injectされる
Full exampleでは以下2つを渡している
binderを受け取る関数(関数の中でbinderにbindしている)
Moduleを継承したクラス
Module
https://injector.readthedocs.io/en/latest/api.html#injector.Module
Configures injector and providers.
InjectorクラスによるとModuleはBinderによってインストールされるらしい
Binder
https://injector.readthedocs.io/en/latest/api.html#injector.Binder
Bind interfaces to implementations.
bindメソッド
binder.bind(A, to=A('some', 'thing'))
binder.bind(A, to=InstanceProvider(A('some', 'thing')))と同じ