8000 How to use injector features in external libraries? · Issue #901 · ets-labs/python-dependency-injector · GitHub
[go: up one dir, main page]

Skip to content
How to use injector features in external libraries? #901
Open
@Valt25

Description

@Valt25

In our project we have plenty of micro services(that are standalone git repositories). Some of them use dependency injector library to manage dependencies.

For some time ago we started using our library(that is internal for company, but external for every service).

We use external container to handle that, but for some reasons, external container, even got callable provider as dependency, but that callable miss any input parameter from origin config:

`
def _get_token(system_token: str):
print('default token in container _get_token callable provider:', system_token)
try:
token = context.token.get()
if token is None:
return system_token
return context.token.get()
except LookupError:
return system_token

class Container(containers.DeclarativeContainer):
config = providers.Configuration()

token = providers.Callable(_get_token, config.system_token)

wiring_config = containers.WiringConfiguration(
    packages=(
        'src',
    ),
)

external_container = providers.Container(
    ExternalContainer,
    token=token,
    config=config,
)

`

I have created github repo, that show this problem https://github.com/Valt25/dependency_injector_issue_show_case.

There you can find several branches, they show different stages of project from naive usage, to container usage and the external library with container usage, and then my approach to fix it according to documentation.

Key changes is shown in README.md and you can see commits` diff.

So maybe I miss something in documentation, or misunderstand concept of dependent containers?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0