Open
Description
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
Metadata
Metadata
Assignees
Labels
No labels