Repository navigation
Expand file tree
/
Copy pathcontext.py
More file actions
46 lines (37 loc) · 1.42 KB
/
Copy pathcontext.py
File metadata and controls
46 lines (37 loc) · 1.42 KB
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
42
43
44
45
46
"""Application context: builds the backend once and wires up the services. Both adapters
obtain capabilities through a single ``AppContext`` (process-wide singleton)."""
from __future__ import annotations
from ..settings import Settings, get_settings
from .backend.duckdb_backend import DuckDBBackend
from .services import (
CitationsService,
ClinicalService,
CohortService,
DiscoveryService,
LicenseService,
ManifestService,
QueryService,
ReleaseService,
ViewerService,
)
class AppContext:
def __init__(self, settings: Settings | None = None):
self.settings = settings or get_settings()
self.backend = DuckDBBackend(self.settings)
self.discovery = DiscoveryService(self.backend)
self.releases = ReleaseService(self.backend)
self.cohort = CohortService(self.backend, self.settings)
self.manifest = ManifestService(self.backend, self.settings)
self.query = QueryService(self.backend, self.settings)
self.clinical = ClinicalService(self.backend, self.settings)
self.viewer = ViewerService(self.backend)
self.citations = CitationsService(self.backend)
self.licenses = LicenseService(self.backend)
def close(self) -> None:
self.backend.close()
_context: AppContext | None = None
def get_context() -> AppContext:
global _context
if _context is None:
_context = AppContext()
return _context