Improved service provider

This commit is contained in:
2021-03-23 21:39:29 +01:00
parent a683b70c5f
commit ca51f88d2b
15 changed files with 93 additions and 194 deletions

View File

@@ -9,6 +9,7 @@ from cpl.dependency_injection.service_provider_abc import ServiceProviderABC
from cpl.logging.logger_abc import LoggerABC
from cpl.mailing.email import EMail
from cpl.mailing.email_client_abc import EMailClientABC
from tests.custom.general.test_service import TestService
class Application(ApplicationABC):
@@ -23,7 +24,7 @@ class Application(ApplicationABC):
mail.add_header('Mime-Version: 1.0')
mail.add_header('Content-Type: text/plain; charset=utf-8')
mail.add_header('Content-Transfer-Encoding: quoted-printable')
mail.add_receiver(' sven.heidemann@sh-edraft.de')
mail.add_receiver('sven.heidemann@sh-edraft.de')
mail.subject = f'Test - {self._configuration.environment.host_name}'
mail.body = 'Dies ist ein Test :D'
self._mailer.send_mail(mail)
@@ -50,6 +51,8 @@ class Application(ApplicationABC):
self._logger.debug(__name__, f'Host: {self._configuration.environment.host_name}')
self._logger.debug(__name__, f'Environment: {self._configuration.environment.environment_name}')
self._logger.debug(__name__, f'Customer: {self._configuration.environment.customer}')
Console.spinner('Test', self._wait, 20, spinner_foreground_color='red')
Console.spinner('Test', self._wait, 2, spinner_foreground_color='red')
test: TestService = self._services.get_service(TestService)
test.run()
# self.test_send_mail()
# self.test_console()

View File

@@ -10,6 +10,7 @@ from cpl.logging.logger_abc import LoggerABC
from cpl.mailing.email_client_service import EMailClient
from cpl.mailing.email_client_abc import EMailClientABC
from cpl.utils.credential_manager import CredentialManager
from tests.custom.general.test_service import TestService
class Startup(StartupABC):
@@ -20,7 +21,6 @@ class Startup(StartupABC):
self._configuration = config
self._application_runtime = runtime
self._services = services
print(self._services)
def configure_configuration(self) -> ConfigurationABC:
self._configuration.add_environment_variables('PYTHON_')
@@ -40,5 +40,6 @@ class Startup(StartupABC):
self._services.add_singleton(LoggerABC, Logger)
self._services.add_singleton(EMailClientABC, EMailClient)
self._services.add_singleton(TestService)
return self._services.build_service_provider()

View File

@@ -0,0 +1,13 @@
from cpl.console.console import Console
from cpl.dependency_injection import ServiceABC, ServiceProviderABC
class TestService(ServiceABC):
def __init__(self, provider: ServiceProviderABC):
ServiceABC.__init__(self)
self._provider = provider
def run(self):
Console.write_line('Hello World!', self._provider)