python-dependency-injector/examples/demo/di.py

29 lines
470 B
Python
Raw Normal View History

2020-09-04 06:21:09 +03:00
import os
2016-03-29 20:17:12 +03:00
2020-09-04 06:21:09 +03:00
class ApiClient:
def __init__(self, api_key: str, timeout: int):
self.api_key = api_key
self.timeout = timeout
2016-03-29 20:17:12 +03:00
2020-09-04 06:21:09 +03:00
class Service:
2016-03-29 20:17:12 +03:00
2020-09-04 06:21:09 +03:00
def __init__(self, api_client: ApiClient):
self.api_client = api_client
2016-03-29 20:17:12 +03:00
2020-09-21 23:46:02 +03:00
def main() -> None:
service = Service(
api_client=ApiClient(
api_key=os.getenv('API_KEY'),
timeout=os.getenv('TIMEOUT'),
),
)
...
2016-03-29 20:17:12 +03:00
if __name__ == '__main__':
2020-09-21 23:46:02 +03:00
main()