from datetime import datetime from typing import Optional from cpl_core.application import StartupABC from cpl_core.configuration import ConfigurationABC from cpl_core.database import DatabaseSettings from cpl_core.dependency_injection import ServiceProviderABC, ServiceCollectionABC from cpl_core.environment import ApplicationEnvironment from bot_data.db_context import DBContext class Startup(StartupABC): def __init__(self): StartupABC.__init__(self) self._start_time = datetime.now() self._config: Optional[ConfigurationABC] = None def configure_configuration(self, configuration: ConfigurationABC, environment: ApplicationEnvironment) -> ConfigurationABC: self._config = configuration return configuration def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC: services.add_logging() services.add_translation() services.add_db_context(DBContext, self._config.get_configuration(DatabaseSettings)) return services.build_service_provider()