forked from vshulcz/injex
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli_app.py
More file actions
41 lines (28 loc) · 888 Bytes
/
cli_app.py
File metadata and controls
41 lines (28 loc) · 888 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from dataclasses import dataclass
from injex import Container
@dataclass(frozen=True)
class Settings:
api_url: str
token: str
class ApiClient:
def __init__(self, settings: Settings):
self.settings = settings
def fetch_status(self) -> str:
return f"connected to {self.settings.api_url}"
class StatusCommand:
def __init__(self, client: ApiClient):
self.client = client
def run(self) -> None:
print(self.client.fetch_status())
def build_container() -> Container:
container = Container()
container.add_instance(
Settings,
Settings(api_url="https://api.example.com", token="dev-token"),
)
container.add_singleton(ApiClient)
container.add_transient(StatusCommand)
return container
if __name__ == "__main__":
container = build_container()
container.resolve(StatusCommand).run()