2022.6.7 - Pipes #69

Merged
edraft merged 4 commits from 2022.6.7 into 2022.6 2022-05-22 20:28:47 +02:00
32 changed files with 190 additions and 65 deletions
Showing only changes of commit cfb8838c73 - Show all commits

View File

@ -14,7 +14,7 @@ class PipeTemplate(TemplateFileABC):
self._class_name = f'{String.first_to_upper(name)}{schematic_upper}' self._class_name = f'{String.first_to_upper(name)}{schematic_upper}'
self._path = path self._path = path
self._value = textwrap.dedent("""\ self._value = textwrap.dedent("""\
from cpl_core.pipe import PipeABC from cpl_core.pipes.pipe_abc import PipeABC
class $Name(PipeABC): class $Name(PipeABC):

View File

@ -5,7 +5,7 @@ from cpl_cli.error import Error
from cpl_core.application.application_abc import ApplicationABC from cpl_core.application.application_abc import ApplicationABC
from cpl_core.configuration.configuration_abc import ConfigurationABC from cpl_core.configuration.configuration_abc import ConfigurationABC
from cpl_core.console.console import Console from cpl_core.console.console import Console
from cpl_core.dependency_injection import ServiceProviderABC from cpl_core.dependency_injection.service_provider_abc import ServiceProviderABC
class CLI(ApplicationABC): class CLI(ApplicationABC):

View File

@ -17,12 +17,12 @@ from cpl_cli.command.version_service import VersionService
from cpl_cli.configuration.workspace_settings import WorkspaceSettings from cpl_cli.configuration.workspace_settings import WorkspaceSettings
from cpl_cli.validators.project_validator import ProjectValidator from cpl_cli.validators.project_validator import ProjectValidator
from cpl_cli.validators.workspace_validator import WorkspaceValidator from cpl_cli.validators.workspace_validator import WorkspaceValidator
from cpl_core.application import StartupExtensionABC from cpl_core.application.startup_extension_abc import StartupExtensionABC
from cpl_core.configuration.argument_type_enum import ArgumentTypeEnum from cpl_core.configuration.argument_type_enum import ArgumentTypeEnum
from cpl_core.configuration.configuration_abc import ConfigurationABC from cpl_core.configuration.configuration_abc import ConfigurationABC
from cpl_core.dependency_injection.service_collection_abc import ServiceCollectionABC from cpl_core.dependency_injection.service_collection_abc import ServiceCollectionABC
from cpl_core.environment import ApplicationEnvironmentABC from cpl_core.environment.application_environment_abc import ApplicationEnvironmentABC
from cpl_core.utils import String from cpl_core.utils.string import String
class StartupArgumentExtension(StartupExtensionABC): class StartupArgumentExtension(StartupExtensionABC):
@ -66,7 +66,7 @@ class StartupArgumentExtension(StartupExtensionABC):
.add_console_argument(ArgumentTypeEnum.Variable, '', 'abc', ['a', 'A'], ' ') \ .add_console_argument(ArgumentTypeEnum.Variable, '', 'abc', ['a', 'A'], ' ') \
.add_console_argument(ArgumentTypeEnum.Variable, '', 'class', ['c', 'C'], ' ') \ .add_console_argument(ArgumentTypeEnum.Variable, '', 'class', ['c', 'C'], ' ') \
.add_console_argument(ArgumentTypeEnum.Variable, '', 'enum', ['e', 'E'], ' ') \ .add_console_argument(ArgumentTypeEnum.Variable, '', 'enum', ['e', 'E'], ' ') \
.add_console_argument(ArgumentTypeEnum.Variable, '', 'pipe', ['p', 'P'], ' ') \ .add_console_argument(ArgumentTypeEnum.Variable, '', 'pipes', ['p', 'P'], ' ') \
.add_console_argument(ArgumentTypeEnum.Variable, '', 'service', ['s', 'S'], ' ') \ .add_console_argument(ArgumentTypeEnum.Variable, '', 'service', ['s', 'S'], ' ') \
.add_console_argument(ArgumentTypeEnum.Variable, '', 'settings', ['st', 'ST'], ' ') \ .add_console_argument(ArgumentTypeEnum.Variable, '', 'settings', ['st', 'ST'], ' ') \
.add_console_argument(ArgumentTypeEnum.Variable, '', 'thread', ['t', 'T'], ' ') \ .add_console_argument(ArgumentTypeEnum.Variable, '', 'thread', ['t', 'T'], ' ') \

View File

@ -15,11 +15,11 @@ __title__ = 'cpl_core'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
__version__ = '2022.6.3' __version__ = '2022.6.7.dev1'
from collections import namedtuple from collections import namedtuple
# imports: # imports:
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2022', minor='6', micro='3') version_info = VersionInfo(major='2022', minor='6', micro='7.dev1')

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_core.application'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
__version__ = '2022.6.3' __version__ = '2022.6.7.dev1'
from collections import namedtuple from collections import namedtuple
@ -28,4 +28,4 @@ from .startup_abc import StartupABC
from .startup_extension_abc import StartupExtensionABC from .startup_extension_abc import StartupExtensionABC
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2022', minor='6', micro='3') version_info = VersionInfo(major='2022', minor='6', micro='7.dev1')

View File

@ -4,7 +4,7 @@ from typing import Optional
from cpl_core.configuration.configuration_abc import ConfigurationABC from cpl_core.configuration.configuration_abc import ConfigurationABC
from cpl_core.console.console import Console from cpl_core.console.console import Console
from cpl_core.dependency_injection.service_provider_abc import ServiceProviderABC from cpl_core.dependency_injection.service_provider_abc import ServiceProviderABC
from cpl_core.environment import ApplicationEnvironmentABC from cpl_core.environment.application_environment_abc import ApplicationEnvironmentABC
class ApplicationABC(ABC): class ApplicationABC(ABC):

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_core.configuration'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
__version__ = '2022.6.3' __version__ = '2022.6.7.dev1'
from collections import namedtuple from collections import namedtuple
@ -34,4 +34,4 @@ from .validator_abc import ValidatorABC
from .variable_argument import VariableArgument from .variable_argument import VariableArgument
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2022', minor='6', micro='3') version_info = VersionInfo(major='2022', minor='6', micro='7.dev1')

View File

@ -1,13 +1,12 @@
import json import json
import os import os
import sys import sys
import traceback
from collections.abc import Callable from collections.abc import Callable
from typing import Union, Type, Optional from typing import Union, Type, Optional
from cpl_cli.command_abc import CommandABC
from cpl_core.configuration.argument_abc import ArgumentABC from cpl_core.configuration.argument_abc import ArgumentABC
from cpl_core.configuration.argument_builder import ArgumentBuilder from cpl_core.configuration.argument_builder import ArgumentBuilder
from cpl_core.configuration.argument_executable_abc import ArgumentExecutableABC
from cpl_core.configuration.argument_type_enum import ArgumentTypeEnum from cpl_core.configuration.argument_type_enum import ArgumentTypeEnum
from cpl_core.configuration.configuration_abc import ConfigurationABC from cpl_core.configuration.configuration_abc import ConfigurationABC
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
@ -306,7 +305,7 @@ class Configuration(ConfigurationABC):
if abort: if abort:
continue continue
cmd: CommandABC = services.get_service(exe.executable_type) cmd: ArgumentExecutableABC = services.get_service(exe.executable_type)
self.add_configuration('ACTIVE_EXECUTABLE', exe.name) self.add_configuration('ACTIVE_EXECUTABLE', exe.name)
cmd.execute(self._additional_arguments) cmd.execute(self._additional_arguments)
prevent = exe.prevent_next_executable prevent = exe.prevent_next_executable

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_core.console'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
__version__ = '2022.6.3' __version__ = '2022.6.7.dev1'
from collections import namedtuple from collections import namedtuple
@ -27,4 +27,4 @@ from .foreground_color_enum import ForegroundColorEnum
from .spinner_thread import SpinnerThread from .spinner_thread import SpinnerThread
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2022', minor='6', micro='3') version_info = VersionInfo(major='2022', minor='6', micro='7.dev1')

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_core.database'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
__version__ = '2022.6.3' __version__ = '2022.6.7.dev1'
from collections import namedtuple from collections import namedtuple
@ -25,4 +25,4 @@ from .database_settings import DatabaseSettings
from .table_abc import TableABC from .table_abc import TableABC
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2022', minor='6', micro='3') version_info = VersionInfo(major='2022', minor='6', micro='7.dev1')

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_core.database.connection'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
__version__ = '2022.6.3' __version__ = '2022.6.7.dev1'
from collections import namedtuple from collections import namedtuple
@ -24,4 +24,4 @@ from .database_connection import DatabaseConnection
from .database_connection_abc import DatabaseConnectionABC from .database_connection_abc import DatabaseConnectionABC
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2022', minor='6', micro='3') version_info = VersionInfo(major='2022', minor='6', micro='7.dev1')

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_core.database.context'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
__version__ = '2022.6.3' __version__ = '2022.6.7.dev1'
from collections import namedtuple from collections import namedtuple
@ -24,4 +24,4 @@ from .database_context import DatabaseContext
from .database_context_abc import DatabaseContextABC from .database_context_abc import DatabaseContextABC
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2022', minor='6', micro='3') version_info = VersionInfo(major='2022', minor='6', micro='7.dev1')

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_core.dependency_injection'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
__version__ = '2022.6.3' __version__ = '2022.6.7.dev1'
from collections import namedtuple from collections import namedtuple
@ -30,4 +30,4 @@ from .service_provider import ServiceProvider
from .service_provider_abc import ServiceProviderABC from .service_provider_abc import ServiceProviderABC
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2022', minor='6', micro='3') version_info = VersionInfo(major='2022', minor='6', micro='7.dev1')

View File

@ -4,6 +4,7 @@ from typing import Optional
from cpl_core.configuration.configuration_abc import ConfigurationABC from cpl_core.configuration.configuration_abc import ConfigurationABC
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
from cpl_core.console import Console
from cpl_core.database.context.database_context_abc import DatabaseContextABC from cpl_core.database.context.database_context_abc import DatabaseContextABC
from cpl_core.dependency_injection.scope_abc import ScopeABC from cpl_core.dependency_injection.scope_abc import ScopeABC
from cpl_core.dependency_injection.scope_builder import ScopeBuilder from cpl_core.dependency_injection.scope_builder import ScopeBuilder

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_core.environment'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
__version__ = '2022.6.3' __version__ = '2022.6.7.dev1'
from collections import namedtuple from collections import namedtuple
@ -25,4 +25,4 @@ from .environment_name_enum import EnvironmentNameEnum
from .application_environment import ApplicationEnvironment from .application_environment import ApplicationEnvironment
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2022', minor='6', micro='3') version_info = VersionInfo(major='2022', minor='6', micro='7.dev1')

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_core.logging'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
__version__ = '2022.6.3' __version__ = '2022.6.7.dev1'
from collections import namedtuple from collections import namedtuple
@ -27,4 +27,4 @@ from .logging_settings import LoggingSettings
from .logging_settings_name_enum import LoggingSettingsNameEnum from .logging_settings_name_enum import LoggingSettingsNameEnum
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2022', minor='6', micro='3') version_info = VersionInfo(major='2022', minor='6', micro='7.dev1')

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_core.mailing'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
__version__ = '2022.6.3' __version__ = '2022.6.7.dev1'
from collections import namedtuple from collections import namedtuple
@ -27,4 +27,4 @@ from .email_client_settings import EMailClientSettings
from .email_client_settings_name_enum import EMailClientSettingsNameEnum from .email_client_settings_name_enum import EMailClientSettingsNameEnum
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2022', minor='6', micro='3') version_info = VersionInfo(major='2022', minor='6', micro='7.dev1')

View File

@ -1,9 +0,0 @@
from cpl_core.pipe.pipe_abc import PipeABC
class FirstCharToLowerPipe(PipeABC):
def __init__(self): pass
def transform(self, value: any, *args):
return f'{value[0].lower()}{value[1:]}'

View File

@ -11,17 +11,22 @@ sh-edraft Common Python library
""" """
__title__ = 'cpl_core.pipe' __title__ = 'cpl_core.pipes'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
__version__ = '2022.6.3' __version__ = '2022.6.7.dev1'
from collections import namedtuple from collections import namedtuple
# imports: # imports:
from .bool_pipe import BoolPipe
from .first_char_to_lower_pipe import FirstCharToLowerPipe from .first_char_to_lower_pipe import FirstCharToLowerPipe
from .first_to_upper_pipe import FirstToUpperPipe
from .ip_address_pipe import IPAddressPipe
from .pipe_abc import PipeABC from .pipe_abc import PipeABC
from .to_camel_case_pipe import ToCamelCasePipe
from .to_snake_case_pipe import ToSnakeCasePipe
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2022', minor='6', micro='3') version_info = VersionInfo(major='2022', minor='6', micro='7.dev1')

View File

@ -0,0 +1,9 @@
from cpl_core.pipes.pipe_abc import PipeABC
class BoolPipe(PipeABC):
def __init__(self): pass
def transform(self, value: bool, *args):
return 'True' if value else 'False'

View File

@ -0,0 +1,20 @@
from cpl_core.pipes.pipe_abc import PipeABC
class FirstCharToLowerPipe(PipeABC):
def __init__(self): pass
def transform(self, value: any, *args):
r"""Converts first char to lower
Parameter
---------
value: :class:`str`
String to convert
Returns
-------
String with first char as lower
"""
return f'{value[0].lower()}{value[1:]}'

View File

@ -0,0 +1,20 @@
from cpl_core.pipes.pipe_abc import PipeABC
class FirstToUpperPipe(PipeABC):
def __init__(self): pass
def transform(self, value: str, *args):
r"""Converts first char to upper
Parameter
---------
chars: :class:`str`
String to convert
Returns
-------
String with first char as upper
"""
return f'{value[0].upper()}{value[1:]}'

View File

@ -0,0 +1,24 @@
from cpl_core.pipes.pipe_abc import PipeABC
class IPAddressPipe(PipeABC):
def __init__(self): pass
def transform(self, value: list[int], *args):
string = ""
if len(value) != 4:
raise Exception('Invalid IP')
for i in range(0, len(value)):
byte = value[i]
if byte > 255:
raise Exception('Invalid IP')
if i == len(value) - 1:
string += f'{byte}'
else:
string += f'{byte}.'
return string

View File

@ -0,0 +1,28 @@
import string
from cpl_core.pipes import PipeABC
class ToCamelCasePipe(PipeABC):
def __init__(self): pass
def transform(self, value: str, *args) -> str:
r"""Converts string to camel case
Parameter
---------
chars: :class:`str`
String to convert
Returns
-------
String converted to CamelCase
"""
converted_name = value
char_set = string.punctuation + ' '
for char in char_set:
if char in converted_name:
converted_name = ''.join(word.title() for word in converted_name.split(char))
return converted_name

View File

@ -0,0 +1,29 @@
import re
from cpl_core.pipes import PipeABC
class ToSnakeCasePipe(PipeABC):
def __init__(self): pass
def transform(self, value: str, *args) -> str:
r"""Converts string to snake case
Parameter
---------
chars: :class:`str`
String to convert
Returns
-------
String converted to snake_case
"""
# convert to train-case to CamelCase
if '-' in value:
value = ''.join(word.title() for word in value.split('-'))
pattern1 = re.compile(r'(.)([A-Z][a-z]+)')
pattern2 = re.compile(r'([a-z0-9])([A-Z])')
file_name = re.sub(pattern1, r'\1_\2', value)
return re.sub(pattern2, r'\1_\2', file_name).lower()

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_core.time'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
__version__ = '2022.6.3' __version__ = '2022.6.7.dev1'
from collections import namedtuple from collections import namedtuple
@ -24,4 +24,4 @@ from .time_format_settings import TimeFormatSettings
from .time_format_settings_names_enum import TimeFormatSettingsNamesEnum from .time_format_settings_names_enum import TimeFormatSettingsNamesEnum
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2022', minor='6', micro='3') version_info = VersionInfo(major='2022', minor='6', micro='7.dev1')

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_core.utils'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
__version__ = '2022.6.3' __version__ = '2022.6.7.dev1'
from collections import namedtuple from collections import namedtuple
@ -25,4 +25,4 @@ from .string import String
from .pip import Pip from .pip import Pip
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2022', minor='6', micro='3') version_info = VersionInfo(major='2022', minor='6', micro='7.dev1')

View File

@ -1,6 +1,5 @@
from cpl_core.application import StartupExtensionABC from cpl_core.application import StartupExtensionABC
from cpl_core.configuration import ConfigurationABC from cpl_core.configuration import ConfigurationABC, ArgumentTypeEnum
from cpl_core.configuration.argument_type_enum import ArgumentTypeEnum
from cpl_core.dependency_injection import ServiceCollectionABC from cpl_core.dependency_injection import ServiceCollectionABC
from cpl_core.environment import ApplicationEnvironmentABC from cpl_core.environment import ApplicationEnvironmentABC
from arguments.generate_argument import GenerateArgument from arguments.generate_argument import GenerateArgument

View File

@ -1,12 +1,10 @@
from cpl_core.application.startup_abc import StartupABC from cpl_core.application import StartupABC
from cpl_core.configuration.configuration_abc import ConfigurationABC from cpl_core.configuration import ConfigurationABC
from cpl_core.dependency_injection.service_collection_abc import ServiceCollectionABC from cpl_core.dependency_injection import ServiceCollectionABC, ServiceProviderABC
from cpl_core.dependency_injection.service_provider_abc import ServiceProviderABC from cpl_core.environment import ApplicationEnvironmentABC
from cpl_core.environment.application_environment_abc import ApplicationEnvironmentABC from cpl_core.logging import Logger, LoggerABC
from cpl_core.logging.logger_service import Logger from cpl_core.mailing import EMailClient, EMailClientABC
from cpl_core.logging.logger_abc import LoggerABC from cpl_core.pipes import IPAddressPipe
from cpl_core.mailing.email_client_service import EMailClient
from cpl_core.mailing.email_client_abc import EMailClientABC
from test_service import TestService from test_service import TestService
@ -27,6 +25,7 @@ class Startup(StartupABC):
def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC) -> ServiceProviderABC: def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC) -> ServiceProviderABC:
services.add_singleton(LoggerABC, Logger) services.add_singleton(LoggerABC, Logger)
services.add_singleton(EMailClientABC, EMailClient) services.add_singleton(EMailClientABC, EMailClient)
services.add_transient(IPAddressPipe)
services.add_singleton(TestService) services.add_singleton(TestService)
return services.build_service_provider() return services.build_service_provider()

View File

@ -1,4 +1,4 @@
from cpl_core.application.application_extension_abc import ApplicationExtensionABC from cpl_core.application import ApplicationExtensionABC
from cpl_core.configuration import ConfigurationABC from cpl_core.configuration import ConfigurationABC
from cpl_core.console import Console from cpl_core.console import Console
from cpl_core.dependency_injection import ServiceProviderABC from cpl_core.dependency_injection import ServiceProviderABC

View File

@ -1,15 +1,16 @@
from abc import ABC
from cpl_core.console.console import Console from cpl_core.console.console import Console
from cpl_core.dependency_injection import ServiceProviderABC from cpl_core.dependency_injection import ServiceProviderABC
from cpl_core.pipes.ip_address_pipe import IPAddressPipe
class TestService(ABC): class TestService:
def __init__(self, provider: ServiceProviderABC): def __init__(self, provider: ServiceProviderABC, ip_pipe: IPAddressPipe):
ABC.__init__(self)
self._provider = provider self._provider = provider
self._ip_pipe = ip_pipe
def run(self): def run(self):
Console.write_line('Hello World!', self._provider) Console.write_line('Hello World!', self._provider)
ip = [192, 168, 178, 30]
Console.write_line(ip, self._ip_pipe.transform(ip))