mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-22 17:47:02 +03:00
da13341453
* Add implementation * Add tests for module and class * Add tests for module and class for string ids * Update tests with typing * Add tests for invalid type of marker * Add docs and the example * Update changelog * Fix Python 3.6 tests and flake8
32 lines
573 B
Python
32 lines
573 B
Python
"""Wiring attribute 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)
|
|
|
|
|
|
service: Service = Provide[Container.service]
|
|
|
|
|
|
class Main:
|
|
|
|
service: Service = Provide[Container.service]
|
|
|
|
|
|
if __name__ == '__main__':
|
|
container = Container()
|
|
container.wire(modules=[sys.modules[__name__]])
|
|
|
|
assert isinstance(service, Service)
|
|
assert isinstance(Main.service, Service)
|