Click

Though it is not required, you can use dishka-click integration. It features automatic injection to command handlers. In contrast with other integrations there is no scope management.

How to use

  1. Import

from dishka import make_container
from dishka.integrations.click import setup_dishka, inject
  1. Create container in group handler and setup it to click context. Pass auto_inject=True unless you want to use @inject decorator explicitly

@click.group()
@click.pass_context
def main(context: click.Context):
    container = make_container(MyProvider())
    setup_dishka(container=container, context=context, auto_inject=True)

Or pass your own inject decorator

@click.group()
@click.pass_context
def main(context: click.Context):
    container = make_container(MyProvider())
    setup_dishka(container=container, context=context, auto_inject=my_inject)
  1. Mark those of your command handlers parameters which are to be injected with FromDishka[]

@main.command(name="hello")
def hello(interactor: FromDishka[Interactor]):
    ...

3a. (optional) decorate them using @inject

@main.command(name="hello")
@inject
def hello(interactor: FromDishka[Interactor]):
    ...