forked from mtusi2026/mtusi2026lab2
Bring the application, own tests, Dockerfile, toolchain, compose stack, migrations, secret generator, restart hook, evidence scripts and CI job from the lab 2 solution commit 8cddb09 unchanged, merge the lab 2 Makefile targets into the lab 3 skeleton Makefile without touching its targets, and append the lab 2 solution variables to the skeleton .env.example. The package version follows the contract version 1.3.0. This is the starting point of the lab 3 cycle: lint, own tests and the offline skeleton check pass before any lab 3 change. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
55 lines
1.9 KiB
Python
55 lines
1.9 KiB
Python
from collections.abc import AsyncIterator
|
|
|
|
from dishka import Provider, Scope, provide
|
|
|
|
from messenger.shared.application.messagebus import EventBus, InMemoryEventPublisher
|
|
from messenger.shared.application.ports import Clock, EventPublisher, IdGenerator, Logger
|
|
from messenger.shared.config import PlatformSettings
|
|
from messenger.shared.infrastructure.clock import MonotonicUtcClock
|
|
from messenger.shared.infrastructure.ids import Uuid7Generator
|
|
from messenger.shared.infrastructure.postgres import Database
|
|
|
|
|
|
class PlatformProvider(Provider):
|
|
def __init__(self, settings: PlatformSettings, logger: Logger) -> None:
|
|
super().__init__()
|
|
self._settings = settings
|
|
self._logger = logger
|
|
|
|
@provide(scope=Scope.APP)
|
|
def settings(self) -> PlatformSettings:
|
|
return self._settings
|
|
|
|
@provide(scope=Scope.APP)
|
|
def logger(self) -> Logger:
|
|
return self._logger
|
|
|
|
@provide(scope=Scope.APP)
|
|
def clock(self) -> Clock:
|
|
return MonotonicUtcClock()
|
|
|
|
@provide(scope=Scope.APP)
|
|
def ids(self) -> IdGenerator:
|
|
return Uuid7Generator()
|
|
|
|
@provide(scope=Scope.APP)
|
|
async def database(self, settings: PlatformSettings) -> AsyncIterator[Database]:
|
|
database = Database(
|
|
settings.database_url.get_secret_value(),
|
|
max_size=settings.db_pool_max_size,
|
|
connect_timeout=settings.db_connect_timeout_seconds,
|
|
acquire_timeout=settings.db_acquire_timeout_seconds,
|
|
command_timeout=settings.db_command_timeout_seconds,
|
|
)
|
|
await database.open()
|
|
yield database
|
|
await database.close()
|
|
|
|
@provide(scope=Scope.APP)
|
|
def event_bus(self, logger: Logger, settings: PlatformSettings) -> EventBus:
|
|
return EventBus(logger, max_queue=settings.event_queue_max)
|
|
|
|
@provide(scope=Scope.APP)
|
|
def publisher(self, bus: EventBus) -> EventPublisher:
|
|
return InMemoryEventPublisher(bus)
|