Added logic to create application

This commit is contained in:
Sven Heidemann 2020-11-26 11:55:55 +01:00
parent c815e75282
commit 1c753aaaea
9 changed files with 66 additions and 14 deletions

View File

@ -20,6 +20,7 @@ __version__ = '2020.12.5'
from collections import namedtuple from collections import namedtuple
# imports: # imports:
from .configuration import Configuration
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major=2020, minor=12, micro=5) version_info = VersionInfo(major=2020, minor=12, micro=5)

View File

@ -20,6 +20,7 @@ __version__ = '2020.12.5'
from collections import namedtuple from collections import namedtuple
# imports: # imports:
from .configuration_base import ConfigurationBase
from .configuration_model_base import ConfigurationModelBase from .configuration_model_base import ConfigurationModelBase
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')

View File

@ -1,17 +1,20 @@
from datetime import datetime from datetime import datetime
from sh_edraft.hosting.hosting_environment import HostingEnvironment
from sh_edraft.hosting.base.application_host_base import ApplicationHostBase from sh_edraft.hosting.base.application_host_base import ApplicationHostBase
from sh_edraft.hosting.base.environment_base import EnvironmentBase from sh_edraft.hosting.base.environment_base import EnvironmentBase
from sh_edraft.service.base import ServiceProviderBase
from sh_edraft.service.service_provider import ServiceProvider from sh_edraft.service.service_provider import ServiceProvider
class ApplicationHost(ApplicationHostBase): class ApplicationHost(ApplicationHostBase):
def __init__(self, name: str, env: EnvironmentBase): def __init__(self, name: str, args: list[str]):
ApplicationHostBase.__init__(self) ApplicationHostBase.__init__(self)
self._name: str = name self._name: str = name
self._environment: EnvironmentBase = env self._environment = HostingEnvironment()
self._args: list[str] = args
self._services = ServiceProvider(self) self._services = ServiceProvider(self)
self._start_time: datetime = datetime.now() self._start_time: datetime = datetime.now()
self._end_time: datetime = datetime.now() self._end_time: datetime = datetime.now()
@ -24,10 +27,6 @@ class ApplicationHost(ApplicationHostBase):
def environment(self) -> EnvironmentBase: def environment(self) -> EnvironmentBase:
return self._environment return self._environment
@property
def services(self):
return self._services
@property @property
def end_time(self) -> datetime: def end_time(self) -> datetime:
return self._end_time return self._end_time
@ -47,3 +46,7 @@ class ApplicationHost(ApplicationHostBase):
@property @property
def date_time_now(self) -> datetime: def date_time_now(self) -> datetime:
return datetime.now() return datetime.now()
@property
def services(self) -> ServiceProviderBase:
return self._services

View File

@ -0,0 +1,16 @@
from abc import ABC, abstractmethod
class ApplicationBase(ABC):
@abstractmethod
def __init__(self): pass
@abstractmethod
def create_configuration(self): pass
@abstractmethod
def create_services(self): pass
@abstractmethod
def main(self): pass

View File

@ -1,14 +1,16 @@
from typing import Optional
from sh_edraft.hosting.base.environment_base import EnvironmentBase from sh_edraft.hosting.base.environment_base import EnvironmentBase
from sh_edraft.hosting.model.environment_name import EnvironmentName from sh_edraft.hosting.model.environment_name import EnvironmentName
class HostingEnvironment(EnvironmentBase): class HostingEnvironment(EnvironmentBase):
def __init__(self, name: EnvironmentName, crp: str): def __init__(self, name: EnvironmentName = None, crp: str = None):
EnvironmentBase.__init__(self) EnvironmentBase.__init__(self)
self._name = name self._name: Optional[EnvironmentName] = name
self._content_root_path = crp self._content_root_path: Optional[str] = crp
@property @property
def name(self) -> EnvironmentName: def name(self) -> EnvironmentName:
@ -17,4 +19,3 @@ class HostingEnvironment(EnvironmentBase):
@property @property
def content_root_path(self) -> str: def content_root_path(self) -> str:
return self._content_root_path return self._content_root_path

View File

@ -11,10 +11,6 @@ class ServiceProviderBase(ServiceBase):
def __init__(self): def __init__(self):
ServiceBase.__init__(self) ServiceBase.__init__(self)
self._transient_services: dict[Type[ServiceBase], Type[ServiceBase]] = {}
self._scoped_services: dict[Type[ServiceBase], Type[ServiceBase]] = {}
self._singleton_services: dict[Type[ServiceBase], ServiceBase] = {}
@property @property
@abstractmethod @abstractmethod
def config(self): pass def config(self): pass

View File

@ -16,6 +16,10 @@ class ServiceProvider(ServiceProviderBase):
self._app_host: ApplicationHostBase = app_host self._app_host: ApplicationHostBase = app_host
self._config = Configuration() self._config = Configuration()
self._transient_services: dict[Type[ServiceBase], Type[ServiceBase]] = {}
self._scoped_services: dict[Type[ServiceBase], Type[ServiceBase]] = {}
self._singleton_services: dict[Type[ServiceBase], ServiceBase] = {}
@property @property
def config(self): def config(self):
return self._config return self._config

View File

30
src/tests_dev/main.py Normal file
View File

@ -0,0 +1,30 @@
import sys
from sh_edraft.hosting import ApplicationHost
from sh_edraft.hosting.base.application_base import ApplicationBase
class Program(ApplicationBase):
def __init__(self):
ApplicationBase.__init__(self)
self._app_host = ApplicationHost('CPL_DEV_Test', sys.argv)
self._config = self._app_host.services.config
self._services = self._app_host.services
def create_configuration(self):
self._config.create()
def create_services(self):
self._services.create()
def main(self):
print('RUN')
if __name__ == '__main__':
program = Program()
program.create_configuration()
program.create_services()
program.main()