2021.4 #19
@ -19,8 +19,8 @@ class ServiceProvider(ServiceProviderABC):
|
|||||||
self._app_runtime: ApplicationRuntimeABC = app_runtime
|
self._app_runtime: ApplicationRuntimeABC = app_runtime
|
||||||
self._database_context: Optional[DatabaseContextABC] = None
|
self._database_context: Optional[DatabaseContextABC] = None
|
||||||
|
|
||||||
self._transient_services: dict[Type[ServiceABC], Type[ServiceABC]] = {}
|
self._transient_services: dict[Type[ServiceABC], Callable[ServiceABC]] = {}
|
||||||
self._scoped_services: dict[Type[ServiceABC], Type[ServiceABC]] = {}
|
self._scoped_services: dict[Type[ServiceABC], Callable[ServiceABC]] = {}
|
||||||
self._singleton_services: dict[Type[ServiceABC], Callable[ServiceABC], ServiceABC] = {}
|
self._singleton_services: dict[Type[ServiceABC], Callable[ServiceABC], ServiceABC] = {}
|
||||||
|
|
||||||
def _create_instance(self, service: Union[Callable[ServiceABC], ServiceABC]) -> Callable[ServiceABC]:
|
def _create_instance(self, service: Union[Callable[ServiceABC], ServiceABC]) -> Callable[ServiceABC]:
|
||||||
@ -52,10 +52,10 @@ class ServiceProvider(ServiceProviderABC):
|
|||||||
def get_db_context(self) -> Callable[DatabaseContextABC]:
|
def get_db_context(self) -> Callable[DatabaseContextABC]:
|
||||||
return self._database_context
|
return self._database_context
|
||||||
|
|
||||||
def add_transient(self, service_type: Type[ServiceABC], service: Type[ServiceABC]):
|
def add_transient(self, service_type: Type[ServiceABC], service: Callable[ServiceABC]):
|
||||||
self._transient_services[service_type] = service
|
self._transient_services[service_type] = service
|
||||||
|
|
||||||
def add_scoped(self, service_type: Type[ServiceABC], service: Type[ServiceABC]):
|
def add_scoped(self, service_type: Type[ServiceABC], service: Callable[ServiceABC]):
|
||||||
self._scoped_services[service_type] = service
|
self._scoped_services[service_type] = service
|
||||||
|
|
||||||
def add_singleton(self, service_type: Type[ServiceABC], service: Callable[ServiceABC]):
|
def add_singleton(self, service_type: Type[ServiceABC], service: Callable[ServiceABC]):
|
||||||
|
@ -18,10 +18,10 @@ class ServiceProviderABC(ABC):
|
|||||||
def get_db_context(self) -> Callable[DatabaseContextABC]: pass
|
def get_db_context(self) -> Callable[DatabaseContextABC]: pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def add_transient(self, service_type: Type, service: Type): pass
|
def add_transient(self, service_type: Type, service: Callable): pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def add_scoped(self, service_type: Type, service: Type): pass
|
def add_scoped(self, service_type: Type, service: Callable): pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def add_singleton(self, service_type: Type, service: Callable): pass
|
def add_singleton(self, service_type: Type, service: Callable): pass
|
||||||
|
Loading…
Reference in New Issue
Block a user