Update demo example

This commit is contained in:
Roman Mogylatov 2021-12-20 15:24:55 +02:00
parent 7e20b7e88d
commit f68b59f9ed
4 changed files with 12 additions and 12 deletions

View File

@ -90,7 +90,7 @@ Key features of the ``Dependency Injector``:
api_client = providers.Singleton(
ApiClient,
api_key=config.api_key,
timeout=config.timeout.as_int(),
timeout=config.timeout,
)
service = providers.Factory(
@ -106,8 +106,8 @@ Key features of the ``Dependency Injector``:
if __name__ == "__main__":
container = Container()
container.config.api_key.from_env("API_KEY")
container.config.timeout.from_env("TIMEOUT")
container.config.api_key.from_env("API_KEY", required=True)
container.config.timeout.from_env("TIMEOUT", as_=int, default=5)
container.wire(modules=[__name__])
main() # <-- dependency is injected automatically

View File

@ -96,7 +96,7 @@ Key features of the ``Dependency Injector``:
api_client = providers.Singleton(
ApiClient,
api_key=config.api_key,
timeout=config.timeout.as_int(),
timeout=config.timeout,
)
service = providers.Factory(
@ -112,8 +112,8 @@ Key features of the ``Dependency Injector``:
if __name__ == "__main__":
container = Container()
container.config.api_key.from_env("API_KEY")
container.config.timeout.from_env("TIMEOUT")
container.config.api_key.from_env("API_KEY", required=True)
container.config.timeout.from_env("TIMEOUT", as_=int, default=5)
container.wire(modules=[__name__])
main() # <-- dependency is injected automatically

View File

@ -172,7 +172,7 @@ the dependency.
api_client = providers.Singleton(
ApiClient,
api_key=config.api_key,
timeout=config.timeout.as_int(),
timeout=config.timeout,
)
service = providers.Factory(
@ -188,8 +188,8 @@ the dependency.
if __name__ == "__main__":
container = Container()
container.config.api_key.from_env("API_KEY")
container.config.timeout.from_env("TIMEOUT")
container.config.api_key.from_env("API_KEY", required=True)
container.config.timeout.from_env("TIMEOUT", as_=int, default=5)
container.wire(modules=[__name__])
main() # <-- dependency is injected automatically

View File

@ -13,7 +13,7 @@ class Container(containers.DeclarativeContainer):
api_client = providers.Singleton(
ApiClient,
api_key=config.api_key,
timeout=config.timeout.as_int(),
timeout=config.timeout,
)
service = providers.Factory(
@ -29,8 +29,8 @@ def main(service: Service = Provide[Container.service]):
if __name__ == "__main__":
container = Container()
container.config.api_key.from_env("API_KEY")
container.config.timeout.from_env("TIMEOUT")
container.config.api_key.from_env("API_KEY", required=True)
container.config.timeout.from_env("TIMEOUT", as_=int, default=5)
container.wire(modules=[__name__])
main() # <-- dependency is injected automatically