Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Possibility of defining dependency parameters for a container on call site #656

Open
wax911 opened this issue Dec 31, 2022 · 0 comments

Comments

@wax911
Copy link

wax911 commented Dec 31, 2022

class Service:
    ...
from dependency_injector import containers, providers


class Container(containers.DeclarativeContainer):
    # obtain `environment` as a passed in parameter
    environment = providers.Dependency()

    # utilise the provided `environment`
    service = providers.Factory(Service, env=environment.provided)
from dependency_injector.wiring import Provide, inject


@inject
def start(service: Service = Provide['service']) -> None:
    ...


if __name__ == "__main__":
    # example of passing a param into our container
    container = Container(environment='DEBUG')
    container.wire(modules=[__name__])

    start()

Given the above example, with a dependency provided as environment I would like to know if something like this exists within the dependency_injector package, I had a look at the documentation and couldn't really figure out a way to achieve this, and this is as far as I got which doesn't work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant