This has been in my mind for some time so I decided to finally write it.
Would that be possible to specify the Injector instance that should be used to inject dependencies? I see it the following way
container = Injector([module])
...
@container.inject # or maybe @inject(container)
def do_something(a: Dependency):
...
My motivation is that I have multiple python modules, each one configuring it's own dependencies so each module (in general) expects different instances of dependencies.
I know that the proposed solution requires a variable container to be defined at interpretation time but not always is that undesireable. What do you think?
My workaround currently is calling container.get but I don't really like it.
Or is there something I don't understand about how injector works and inject chooses "the most local" container?
This has been in my mind for some time so I decided to finally write it.
Would that be possible to specify the
Injectorinstance that should be used to inject dependencies? I see it the following wayMy motivation is that I have multiple python modules, each one configuring it's own dependencies so each module (in general) expects different instances of dependencies.
I know that the proposed solution requires a variable
containerto be defined at interpretation time but not always is that undesireable. What do you think?My workaround currently is calling
container.getbut I don't really like it.Or is there something I don't understand about how injector works and
injectchooses "the most local" container?