2021-03-01 02:07:50 +00:00
|
|
|
"""Wiring attribute example."""
|
|
|
|
|
|
|
|
from dependency_injector import containers, providers
|
|
|
|
from dependency_injector.wiring import Provide
|
|
|
|
|
|
|
|
|
|
|
|
class Service:
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
|
|
class Container(containers.DeclarativeContainer):
|
|
|
|
|
|
|
|
service = providers.Factory(Service)
|
|
|
|
|
|
|
|
|
|
|
|
service: Service = Provide[Container.service]
|
|
|
|
|
|
|
|
|
|
|
|
class Main:
|
|
|
|
|
|
|
|
service: Service = Provide[Container.service]
|
|
|
|
|
|
|
|
|
2021-09-30 19:03:19 +00:00
|
|
|
if __name__ == "__main__":
|
2021-03-01 02:07:50 +00:00
|
|
|
container = Container()
|
2021-09-30 19:03:19 +00:00
|
|
|
container.wire(modules=[__name__])
|
2021-03-01 02:07:50 +00:00
|
|
|
|
|
|
|
assert isinstance(service, Service)
|
|
|
|
assert isinstance(Main.service, Service)
|