Skip to content

use specific Injector instance as inject decorator #249

@r2rstep

Description

@r2rstep

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions