mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-30 05:23:59 +03:00
27 lines
451 B
Python
27 lines
451 B
Python
|
"""Wiring example."""
|
||
|
|
||
|
import sys
|
||
|
|
||
|
from dependency_injector import containers, providers
|
||
|
from dependency_injector.wiring import Provide
|
||
|
|
||
|
|
||
|
class Service:
|
||
|
...
|
||
|
|
||
|
|
||
|
class Container(containers.DeclarativeContainer):
|
||
|
|
||
|
service = providers.Factory(Service)
|
||
|
|
||
|
|
||
|
def main(service: Service = Provide[Container.service]) -> None:
|
||
|
...
|
||
|
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
container = Container()
|
||
|
container.wire(modules=[sys.modules[__name__]])
|
||
|
|
||
|
main()
|