From e23f4187fecfdb95f8c9bce247061d562e546602 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Wed, 25 May 2022 18:42:47 +0200 Subject: [PATCH] Added logic to add internal pipes in ServiceCollection --- src/cpl_core/dependency_injection/service_collection.py | 6 ++++++ src/cpl_core/dependency_injection/service_collection_abc.py | 5 +++++ tools/set_version/startup.py | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/cpl_core/dependency_injection/service_collection.py b/src/cpl_core/dependency_injection/service_collection.py index 6a7c6f0d..110c8c43 100644 --- a/src/cpl_core/dependency_injection/service_collection.py +++ b/src/cpl_core/dependency_injection/service_collection.py @@ -1,6 +1,7 @@ from typing import Union, Type, Callable, Optional from cpl_core.configuration.configuration_abc import ConfigurationABC +from cpl_core.console import Console from cpl_core.database.context.database_context_abc import DatabaseContextABC from cpl_core.database.database_settings import DatabaseSettings from cpl_core.dependency_injection.service_collection_abc import ServiceCollectionABC @@ -10,6 +11,7 @@ from cpl_core.dependency_injection.service_provider import ServiceProvider from cpl_core.dependency_injection.service_provider_abc import ServiceProviderABC from cpl_core.logging.logger_abc import LoggerABC from cpl_core.logging.logger_service import Logger +from cpl_core.pipes.pipe_abc import PipeABC class ServiceCollection(ServiceCollectionABC): @@ -53,6 +55,10 @@ class ServiceCollection(ServiceCollectionABC): def add_logging(self): self.add_singleton(LoggerABC, Logger) + def add_pipes(self): + for pipe in PipeABC.__subclasses__(): + self.add_transient(PipeABC, pipe) + def add_singleton(self, service_type: Union[type, object], service: Union[type, object] = None): self._add_descriptor_by_lifetime(service_type, ServiceLifetimeEnum.singleton, service) return self diff --git a/src/cpl_core/dependency_injection/service_collection_abc.py b/src/cpl_core/dependency_injection/service_collection_abc.py index 13ddca96..5c828388 100644 --- a/src/cpl_core/dependency_injection/service_collection_abc.py +++ b/src/cpl_core/dependency_injection/service_collection_abc.py @@ -30,6 +30,11 @@ class ServiceCollectionABC(ABC): r"""Adds the CPL internal logger""" pass + @abstractmethod + def add_pipes(self): + r"""Adds the CPL internal pipes as transient""" + pass + @abstractmethod def add_transient(self, service_type: Type, service: Callable = None) -> 'ServiceCollectionABC': r"""Adds a service with transient lifetime diff --git a/tools/set_version/startup.py b/tools/set_version/startup.py index ec9c6cf2..31c8a268 100644 --- a/tools/set_version/startup.py +++ b/tools/set_version/startup.py @@ -24,8 +24,8 @@ class Startup(StartupABC): return configuration def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC: + services.add_pipes() services.add_transient(GitService) services.add_transient(VersionSetterService) - services.add_transient(VersionPipe) return services.build_service_provider()