2021-01-11 16:18:02 +03:00
|
|
|
"""Wiring container injection example."""
|
|
|
|
|
|
|
|
from dependency_injector import containers, providers
|
2021-09-30 22:03:19 +03:00
|
|
|
from dependency_injector.wiring import Provide, inject
|
2021-01-11 16:18:02 +03:00
|
|
|
|
|
|
|
|
|
|
|
class Service:
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
|
|
class Container(containers.DeclarativeContainer):
|
|
|
|
|
|
|
|
service = providers.Factory(Service)
|
|
|
|
|
|
|
|
|
|
|
|
@inject
|
|
|
|
def main(container: Container = Provide[Container]):
|
|
|
|
service = container.service()
|
|
|
|
...
|
|
|
|
|
|
|
|
|
2021-09-30 22:03:19 +03:00
|
|
|
if __name__ == "__main__":
|
2021-01-11 16:18:02 +03:00
|
|
|
container = Container()
|
2021-09-30 22:03:19 +03:00
|
|
|
container.wire(modules=[__name__])
|
2021-01-11 16:18:02 +03:00
|
|
|
|
|
|
|
main()
|