python-dependency-injector/examples/wiring/example.py
2021-09-29 09:02:59 -04:00

26 lines
444 B
Python

"""Wiring example."""
from dependency_injector import containers, providers
from dependency_injector.wiring import inject, Provide
class Service:
...
class Container(containers.DeclarativeContainer):
service = providers.Factory(Service)
@inject
def main(service: Service = Provide[Container.service]) -> None:
...
if __name__ == '__main__':
container = Container()
container.wire(modules=["__main__"])
main()