Added first version of database and orm
This commit is contained in:
@@ -1,15 +1,21 @@
|
||||
from abc import abstractmethod
|
||||
from abc import abstractmethod, ABC
|
||||
from collections import Callable
|
||||
from typing import Type
|
||||
|
||||
from sh_edraft.database.context.base.database_context_base import DatabaseContextBase
|
||||
from sh_edraft.service.base.service_base import ServiceBase
|
||||
|
||||
|
||||
class ServiceProviderBase(ServiceBase):
|
||||
class ServiceProviderBase(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
ServiceBase.__init__(self)
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
def add_db_context(self, db_context: Type[DatabaseContextBase]): pass
|
||||
|
||||
@abstractmethod
|
||||
def get_db_context(self) -> Callable[DatabaseContextBase]: pass
|
||||
|
||||
@abstractmethod
|
||||
def add_transient(self, service_type: Type[ServiceBase], service: Type[ServiceBase]): pass
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
from collections import Callable
|
||||
from inspect import signature, Parameter
|
||||
from typing import Type
|
||||
from typing import Type, Optional
|
||||
|
||||
from sh_edraft.configuration.base.configuration_model_base import ConfigurationModelBase
|
||||
from sh_edraft.database.context.base.database_context_base import DatabaseContextBase
|
||||
from sh_edraft.hosting.base.application_runtime_base import ApplicationRuntimeBase
|
||||
from sh_edraft.service.providing.base.service_provider_base import ServiceProviderBase
|
||||
from sh_edraft.service.base.service_base import ServiceBase
|
||||
@@ -13,6 +14,7 @@ class ServiceProvider(ServiceProviderBase):
|
||||
def __init__(self, app_runtime: ApplicationRuntimeBase):
|
||||
ServiceProviderBase.__init__(self)
|
||||
self._app_runtime: ApplicationRuntimeBase = app_runtime
|
||||
self._database_context: Optional[DatabaseContextBase] = None
|
||||
|
||||
self._transient_services: dict[Type[ServiceBase], Type[ServiceBase]] = {}
|
||||
self._scoped_services: dict[Type[ServiceBase], Type[ServiceBase]] = {}
|
||||
@@ -29,6 +31,9 @@ class ServiceProvider(ServiceProviderBase):
|
||||
if issubclass(parameter.annotation, ApplicationRuntimeBase):
|
||||
params.append(self._app_runtime)
|
||||
|
||||
elif issubclass(parameter.annotation, DatabaseContextBase):
|
||||
params.append(self._database_context)
|
||||
|
||||
elif issubclass(parameter.annotation, ServiceBase):
|
||||
params.append(self.get_service(parameter.annotation))
|
||||
|
||||
@@ -37,6 +42,12 @@ class ServiceProvider(ServiceProviderBase):
|
||||
|
||||
return service(*params)
|
||||
|
||||
def add_db_context(self, db_context: Type[DatabaseContextBase]):
|
||||
self._database_context = self._create_instance(db_context)
|
||||
|
||||
def get_db_context(self) -> Callable[DatabaseContextBase]:
|
||||
return self._database_context
|
||||
|
||||
def add_transient(self, service_type: Type[ServiceBase], service: Type[ServiceBase]):
|
||||
self._transient_services[service_type] = service
|
||||
|
||||
|
||||
Reference in New Issue
Block a user